mirror of
https://github.com/servo/servo.git
synced 2025-08-02 20:20:14 +01:00
webgpu: Implement ShaderCompilationInfo (#32642)
* ShaderCompilationInfo * expectations * Handle CompilationInfo promise in GPUShaderModule * Fix my english
This commit is contained in:
parent
bd0a5eb4b7
commit
c0105de82b
9 changed files with 22103 additions and 682 deletions
|
@ -170,7 +170,12 @@ DOMInterfaces = {
|
|||
|
||||
'GPUDevice': {
|
||||
'weakReferenceable': True, # for usage in GlobalScope https://github.com/servo/servo/issues/32519
|
||||
'inRealms': ['PopErrorScope', 'CreateComputePipelineAsync', 'CreateRenderPipelineAsync'],
|
||||
'inRealms': [
|
||||
'PopErrorScope',
|
||||
'CreateComputePipelineAsync',
|
||||
'CreateRenderPipelineAsync',
|
||||
'CreateShaderModule' # Creates promise for compilation info
|
||||
],
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,23 +4,52 @@
|
|||
|
||||
use dom_struct::dom_struct;
|
||||
use js::jsval::JSVal;
|
||||
use webgpu::ShaderCompilationInfo;
|
||||
|
||||
use super::bindings::codegen::Bindings::WebGPUBinding::GPUCompilationInfoMethods;
|
||||
use super::bindings::root::Dom;
|
||||
use super::bindings::import::module::DomRoot;
|
||||
use super::bindings::reflector::reflect_dom_object_with_proto;
|
||||
use super::bindings::utils::to_frozen_array;
|
||||
use super::types::GPUCompilationMessage;
|
||||
use crate::dom::bindings::reflector::Reflector;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::script_runtime::JSContext;
|
||||
|
||||
#[dom_struct]
|
||||
pub struct GPUCompilationInfo {
|
||||
reflector_: Reflector,
|
||||
msg: Dom<GPUCompilationMessage>,
|
||||
// currently we only get one message from wgpu
|
||||
msg: Vec<DomRoot<GPUCompilationMessage>>,
|
||||
}
|
||||
|
||||
// TODO: wgpu does not expose right fields right now
|
||||
impl GPUCompilationInfoMethods for GPUCompilationInfo {
|
||||
/// <https://gpuweb.github.io/gpuweb/#dom-gpucompilationinfo-messages>
|
||||
fn Messages(&self, _cx: JSContext) -> JSVal {
|
||||
todo!()
|
||||
impl GPUCompilationInfo {
|
||||
pub fn new_inherited(msg: Vec<DomRoot<GPUCompilationMessage>>) -> Self {
|
||||
Self {
|
||||
reflector_: Reflector::new(),
|
||||
msg,
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn new(global: &GlobalScope, msg: Vec<DomRoot<GPUCompilationMessage>>) -> DomRoot<Self> {
|
||||
reflect_dom_object_with_proto(Box::new(Self::new_inherited(msg)), global, None)
|
||||
}
|
||||
|
||||
pub fn from(global: &GlobalScope, error: Option<ShaderCompilationInfo>) -> DomRoot<Self> {
|
||||
Self::new(
|
||||
global,
|
||||
if let Some(error) = error {
|
||||
vec![GPUCompilationMessage::from(global, error)]
|
||||
} else {
|
||||
Vec::new()
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl GPUCompilationInfoMethods for GPUCompilationInfo {
|
||||
/// <https://gpuweb.github.io/gpuweb/#dom-gpucompilationinfo-messages>
|
||||
fn Messages(&self, cx: JSContext) -> JSVal {
|
||||
to_frozen_array(self.msg.as_slice(), cx)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#![allow(dead_code)] // this file is stub as wgpu does not provide info
|
||||
|
||||
use dom_struct::dom_struct;
|
||||
use webgpu::ShaderCompilationInfo;
|
||||
|
||||
use super::bindings::codegen::Bindings::WebGPUBinding::{
|
||||
GPUCompilationMessageMethods, GPUCompilationMessageType,
|
||||
|
@ -62,6 +63,18 @@ impl GPUCompilationMessage {
|
|||
global,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn from(global: &GlobalScope, info: ShaderCompilationInfo) -> DomRoot<Self> {
|
||||
GPUCompilationMessage::new(
|
||||
global,
|
||||
info.message.into(),
|
||||
GPUCompilationMessageType::Error,
|
||||
info.line_number as u64,
|
||||
info.line_pos as u64,
|
||||
info.offset as u64,
|
||||
info.length as u64,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl GPUCompilationMessageMethods for GPUCompilationMessage {
|
||||
|
|
|
@ -539,13 +539,22 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
fn CreateShaderModule(
|
||||
&self,
|
||||
descriptor: RootedTraceableBox<GPUShaderModuleDescriptor>,
|
||||
comp: InRealm,
|
||||
) -> DomRoot<GPUShaderModule> {
|
||||
let program_id = self
|
||||
.global()
|
||||
.wgpu_id_hub()
|
||||
.lock()
|
||||
.create_shader_module_id(self.device.0.backend());
|
||||
|
||||
let promise = Promise::new_in_current_realm(comp);
|
||||
let shader_module = GPUShaderModule::new(
|
||||
&self.global(),
|
||||
self.channel.clone(),
|
||||
webgpu::WebGPUShaderModule(program_id),
|
||||
descriptor.parent.label.clone().unwrap_or_default(),
|
||||
promise.clone(),
|
||||
);
|
||||
let sender = response_async(&promise, &*shader_module);
|
||||
self.channel
|
||||
.0
|
||||
.send(WebGPURequest::CreateShaderModule {
|
||||
|
@ -553,16 +562,10 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
program_id,
|
||||
program: descriptor.code.0.clone(),
|
||||
label: None,
|
||||
sender,
|
||||
})
|
||||
.expect("Failed to create WebGPU ShaderModule");
|
||||
|
||||
let shader_module = webgpu::WebGPUShaderModule(program_id);
|
||||
GPUShaderModule::new(
|
||||
&self.global(),
|
||||
self.channel.clone(),
|
||||
shader_module,
|
||||
descriptor.parent.label.clone().unwrap_or_default(),
|
||||
)
|
||||
shader_module
|
||||
}
|
||||
|
||||
/// <https://gpuweb.github.io/gpuweb/#dom-gpudevice-createcomputepipeline>
|
||||
|
@ -1029,7 +1032,7 @@ impl AsyncWGPUListener for GPUDevice {
|
|||
promise.resolve_native(&error);
|
||||
},
|
||||
},
|
||||
_ => unreachable!("Wrong response recived on AsyncWGPUListener for GPUDevice"),
|
||||
_ => unreachable!("Wrong response received on AsyncWGPUListener for GPUDevice"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -486,7 +486,6 @@ dictionary GPUPipelineLayoutDescriptor : GPUObjectDescriptorBase {
|
|||
|
||||
[Exposed=(Window, DedicatedWorker), Serializable, Pref="dom.webgpu.enabled"]
|
||||
interface GPUShaderModule {
|
||||
[Throws]
|
||||
Promise<GPUCompilationInfo> getCompilationInfo();
|
||||
};
|
||||
GPUShaderModule includes GPUObjectBase;
|
||||
|
@ -515,9 +514,8 @@ interface GPUCompilationMessage {
|
|||
|
||||
[Exposed=(Window, DedicatedWorker), Pref="dom.webgpu.enabled"]
|
||||
interface GPUCompilationInfo {
|
||||
// codegen hates it
|
||||
//[Cached, Frozen, Pure]
|
||||
readonly attribute /*sequence<GPUCompilationMessage>*/ any messages;
|
||||
//readonly attribute FrozenArray<GPUCompilationMessage> messages;
|
||||
readonly attribute any messages;
|
||||
};
|
||||
|
||||
enum GPUAutoLayoutMode {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue