diff options
author | Samson <16504129+sagudev@users.noreply.github.com> | 2024-07-02 15:39:06 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-02 13:39:06 +0000 |
commit | c0105de82b3d6259d4359062b98d6fbfabf1c139 (patch) | |
tree | 361baf4c648d74249610e6eb01f87b5f2361667f /components/script/dom/gpushadermodule.rs | |
parent | bd0a5eb4b7df0c9ce731277a97cdb21cfdbdb9fb (diff) | |
download | servo-c0105de82b3d6259d4359062b98d6fbfabf1c139.tar.gz servo-c0105de82b3d6259d4359062b98d6fbfabf1c139.zip |
webgpu: Implement ShaderCompilationInfo (#32642)
* ShaderCompilationInfo
* expectations
* Handle CompilationInfo promise in GPUShaderModule
* Fix my english
Diffstat (limited to 'components/script/dom/gpushadermodule.rs')
-rw-r--r-- | components/script/dom/gpushadermodule.rs | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/components/script/dom/gpushadermodule.rs b/components/script/dom/gpushadermodule.rs index 26f9fad8388..ceeb55d0025 100644 --- a/components/script/dom/gpushadermodule.rs +++ b/components/script/dom/gpushadermodule.rs @@ -5,13 +5,14 @@ use std::rc::Rc; use dom_struct::dom_struct; -use webgpu::{WebGPU, WebGPURequest, WebGPUShaderModule}; +use webgpu::{WebGPU, WebGPURequest, WebGPUResponse, WebGPUResponseResult, WebGPUShaderModule}; -use super::bindings::error::Fallible; +use super::gpu::AsyncWGPUListener; +use super::gpucompilationinfo::GPUCompilationInfo; use super::promise::Promise; use crate::dom::bindings::cell::DomRefCell; use crate::dom::bindings::codegen::Bindings::WebGPUBinding::GPUShaderModuleMethods; -use crate::dom::bindings::reflector::{reflect_dom_object, Reflector}; +use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector}; use crate::dom::bindings::root::DomRoot; use crate::dom::bindings::str::USVString; use crate::dom::globalscope::GlobalScope; @@ -25,15 +26,23 @@ pub struct GPUShaderModule { label: DomRefCell<USVString>, #[no_trace] shader_module: WebGPUShaderModule, + #[ignore_malloc_size_of = "promise"] + compilation_info_promise: Rc<Promise>, } impl GPUShaderModule { - fn new_inherited(channel: WebGPU, shader_module: WebGPUShaderModule, label: USVString) -> Self { + fn new_inherited( + channel: WebGPU, + shader_module: WebGPUShaderModule, + label: USVString, + promise: Rc<Promise>, + ) -> Self { Self { reflector_: Reflector::new(), channel, label: DomRefCell::new(label), shader_module, + compilation_info_promise: promise, } } @@ -42,12 +51,14 @@ impl GPUShaderModule { channel: WebGPU, shader_module: WebGPUShaderModule, label: USVString, + promise: Rc<Promise>, ) -> DomRoot<Self> { reflect_dom_object( Box::new(GPUShaderModule::new_inherited( channel, shader_module, label, + promise, )), global, ) @@ -72,8 +83,20 @@ impl GPUShaderModuleMethods for GPUShaderModule { } /// <https://gpuweb.github.io/gpuweb/#dom-gpushadermodule-getcompilationinfo> - fn GetCompilationInfo(&self) -> Fallible<Rc<Promise>> { - todo!("Missing in wgpu: https://github.com/gfx-rs/wgpu/issues/2170") + fn GetCompilationInfo(&self) -> Rc<Promise> { + self.compilation_info_promise.clone() + } +} + +impl AsyncWGPUListener for GPUShaderModule { + fn handle_response(&self, response: Option<WebGPUResponseResult>, promise: &Rc<Promise>) { + match response { + Some(Ok(WebGPUResponse::CompilationInfo(info))) => { + let info = GPUCompilationInfo::from(&self.global(), info); + promise.resolve_native(&info); + }, + _ => unreachable!("Wrong response received on AsyncWGPUListener for GPUShaderModule"), + } } } |