aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/webgpu/gpushadermodule.rs
diff options
context:
space:
mode:
authorwebbeef <me@webbeef.org>2025-03-23 11:52:46 -0700
committerGitHub <noreply@github.com>2025-03-23 18:52:46 +0000
commit1c9f486f88b23b575317ee0b2462e26fba07c5f4 (patch)
tree17274d9605e8ea494623bafe6755ce5cccaaf245 /components/script/dom/webgpu/gpushadermodule.rs
parent4814cbdb1f09e97be70f7c72defee19e67fff473 (diff)
downloadservo-1c9f486f88b23b575317ee0b2462e26fba07c5f4.tar.gz
servo-1c9f486f88b23b575317ee0b2462e26fba07c5f4.zip
webgpu: leverage routed_promise in calls returning promises (#35859)
Using the RoutedPromiseListener let us define a different response type for each promise. This removes unreachable branches that used to exist when they all shared the same WebGPUResponse. Signed-off-by: webbeef <me@webbeef.org>
Diffstat (limited to 'components/script/dom/webgpu/gpushadermodule.rs')
-rw-r--r--components/script/dom/webgpu/gpushadermodule.rs25
1 files changed, 12 insertions, 13 deletions
diff --git a/components/script/dom/webgpu/gpushadermodule.rs b/components/script/dom/webgpu/gpushadermodule.rs
index 62dd456a054..a970e6dbf10 100644
--- a/components/script/dom/webgpu/gpushadermodule.rs
+++ b/components/script/dom/webgpu/gpushadermodule.rs
@@ -5,9 +5,8 @@
use std::rc::Rc;
use dom_struct::dom_struct;
-use webgpu::{WebGPU, WebGPURequest, WebGPUResponse, WebGPUShaderModule};
+use webgpu::{ShaderCompilationInfo, WebGPU, WebGPURequest, WebGPUShaderModule};
-use super::gpu::AsyncWGPUListener;
use super::gpucompilationinfo::GPUCompilationInfo;
use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{
@@ -20,8 +19,8 @@ use crate::dom::bindings::trace::RootedTraceableBox;
use crate::dom::globalscope::GlobalScope;
use crate::dom::promise::Promise;
use crate::dom::types::GPUDevice;
-use crate::dom::webgpu::gpu::response_async;
use crate::realms::InRealm;
+use crate::routed_promise::{RoutedPromiseListener, route_promise};
use crate::script_runtime::CanGc;
#[dom_struct]
@@ -96,7 +95,7 @@ impl GPUShaderModule {
promise.clone(),
can_gc,
);
- let sender = response_async(&promise, &*shader_module);
+ let sender = route_promise(&promise, &*shader_module);
device
.channel()
.0
@@ -129,15 +128,15 @@ impl GPUShaderModuleMethods<crate::DomTypeHolder> for GPUShaderModule {
}
}
-impl AsyncWGPUListener for GPUShaderModule {
- fn handle_response(&self, response: WebGPUResponse, promise: &Rc<Promise>, can_gc: CanGc) {
- match response {
- WebGPUResponse::CompilationInfo(info) => {
- let info = GPUCompilationInfo::from(&self.global(), info, can_gc);
- promise.resolve_native(&info, can_gc);
- },
- _ => unreachable!("Wrong response received on AsyncWGPUListener for GPUShaderModule"),
- }
+impl RoutedPromiseListener<Option<ShaderCompilationInfo>> for GPUShaderModule {
+ fn handle_response(
+ &self,
+ response: Option<ShaderCompilationInfo>,
+ promise: &Rc<Promise>,
+ can_gc: CanGc,
+ ) {
+ let info = GPUCompilationInfo::from(&self.global(), response, can_gc);
+ promise.resolve_native(&info, can_gc);
}
}