mirror of
https://github.com/servo/servo.git
synced 2025-07-29 10:10:34 +01:00
Auto merge of #27447 - kunalmohan:gpu-error, r=kvark
Refactor and improve GPUErrorScopes - Remove use of equivalent BGLs - Capture errors from more `Createxxx` operations - Address crashes on macOS in #27402 Improved ErrorScope model attempts to- 1. Identify and report `OutOfMemoryError` separately. 1. Match `GPUErrorFilter` and pass on uncaptured errors to parent scope. r?@kvark <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [ ] These changes fix #___ (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
This commit is contained in:
commit
f0ba895c68
11 changed files with 259 additions and 149 deletions
|
@ -169,7 +169,6 @@ use time::{Duration, Timespec, Tm};
|
|||
use uuid::Uuid;
|
||||
use webgpu::{
|
||||
wgpu::command::{ComputePass, RenderBundleEncoder, RenderPass},
|
||||
wgt::BindGroupLayoutEntry,
|
||||
WebGPU, WebGPUAdapter, WebGPUBindGroup, WebGPUBindGroupLayout, WebGPUBuffer,
|
||||
WebGPUCommandBuffer, WebGPUCommandEncoder, WebGPUComputePipeline, WebGPUDevice,
|
||||
WebGPUPipelineLayout, WebGPUQueue, WebGPURenderBundle, WebGPURenderPipeline, WebGPUSampler,
|
||||
|
@ -629,7 +628,6 @@ unsafe_no_jsmanaged_fields!(WebGPUContextId);
|
|||
unsafe_no_jsmanaged_fields!(WebGPUCommandBuffer);
|
||||
unsafe_no_jsmanaged_fields!(WebGPUCommandEncoder);
|
||||
unsafe_no_jsmanaged_fields!(WebGPUDevice);
|
||||
unsafe_no_jsmanaged_fields!(BindGroupLayoutEntry);
|
||||
unsafe_no_jsmanaged_fields!(Option<RenderPass>);
|
||||
unsafe_no_jsmanaged_fields!(Option<RenderBundleEncoder>);
|
||||
unsafe_no_jsmanaged_fields!(Option<ComputePass>);
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
use crate::dom::bindings::cell::{DomRefCell, RefMut};
|
||||
use crate::dom::bindings::codegen::Bindings::BroadcastChannelBinding::BroadcastChannelMethods;
|
||||
use crate::dom::bindings::codegen::Bindings::EventSourceBinding::EventSourceBinding::EventSourceMethods;
|
||||
use crate::dom::bindings::codegen::Bindings::GPUValidationErrorBinding::GPUError;
|
||||
use crate::dom::bindings::codegen::Bindings::ImageBitmapBinding::{
|
||||
ImageBitmapOptions, ImageBitmapSource,
|
||||
};
|
||||
|
@ -36,8 +35,6 @@ use crate::dom::eventsource::EventSource;
|
|||
use crate::dom::eventtarget::EventTarget;
|
||||
use crate::dom::file::File;
|
||||
use crate::dom::gpudevice::GPUDevice;
|
||||
use crate::dom::gpuoutofmemoryerror::GPUOutOfMemoryError;
|
||||
use crate::dom::gpuvalidationerror::GPUValidationError;
|
||||
use crate::dom::htmlscriptelement::{ScriptId, SourceCode};
|
||||
use crate::dom::identityhub::Identities;
|
||||
use crate::dom::imagebitmap::ImageBitmap;
|
||||
|
@ -3023,18 +3020,12 @@ impl GlobalScope {
|
|||
let _ = self.gpu_devices.borrow_mut().remove(&device);
|
||||
}
|
||||
|
||||
pub fn handle_wgpu_msg(&self, device: WebGPUDevice, scope: u64, result: WebGPUOpResult) {
|
||||
let result = match result {
|
||||
WebGPUOpResult::Success => Ok(()),
|
||||
WebGPUOpResult::ValidationError(m) => {
|
||||
let val_err = GPUValidationError::new(&self, DOMString::from_string(m));
|
||||
Err(GPUError::GPUValidationError(val_err))
|
||||
},
|
||||
WebGPUOpResult::OutOfMemoryError => {
|
||||
let oom_err = GPUOutOfMemoryError::new(&self);
|
||||
Err(GPUError::GPUOutOfMemoryError(oom_err))
|
||||
},
|
||||
};
|
||||
pub fn handle_wgpu_msg(
|
||||
&self,
|
||||
device: WebGPUDevice,
|
||||
scope: Option<u64>,
|
||||
result: WebGPUOpResult,
|
||||
) {
|
||||
self.gpu_devices
|
||||
.borrow()
|
||||
.get(&device)
|
||||
|
|
|
@ -16,20 +16,20 @@ use crate::dom::bindings::codegen::UnionTypes::{
|
|||
use crate::dom::bindings::num::Finite;
|
||||
use crate::dom::bindings::reflector::DomObject;
|
||||
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
|
||||
use crate::dom::bindings::root::DomRoot;
|
||||
use crate::dom::bindings::root::{Dom, DomRoot};
|
||||
use crate::dom::bindings::str::USVString;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::gpubuffer::GPUBuffer;
|
||||
use crate::dom::gpucommandbuffer::GPUCommandBuffer;
|
||||
use crate::dom::gpucomputepassencoder::GPUComputePassEncoder;
|
||||
use crate::dom::gpudevice::{convert_texture_size_to_dict, convert_texture_size_to_wgt};
|
||||
use crate::dom::gpudevice::{convert_texture_size_to_dict, convert_texture_size_to_wgt, GPUDevice};
|
||||
use crate::dom::gpurenderpassencoder::GPURenderPassEncoder;
|
||||
use dom_struct::dom_struct;
|
||||
use std::borrow::Cow;
|
||||
use std::cell::Cell;
|
||||
use std::collections::HashSet;
|
||||
use webgpu::wgpu::command as wgpu_com;
|
||||
use webgpu::{self, wgt, WebGPU, WebGPUDevice, WebGPURequest};
|
||||
use webgpu::{self, wgt, WebGPU, WebGPURequest};
|
||||
|
||||
// https://gpuweb.github.io/gpuweb/#enumdef-encoder-state
|
||||
#[derive(MallocSizeOf, PartialEq)]
|
||||
|
@ -49,14 +49,14 @@ pub struct GPUCommandEncoder {
|
|||
encoder: webgpu::WebGPUCommandEncoder,
|
||||
buffers: DomRefCell<HashSet<DomRoot<GPUBuffer>>>,
|
||||
state: DomRefCell<GPUCommandEncoderState>,
|
||||
device: WebGPUDevice,
|
||||
device: Dom<GPUDevice>,
|
||||
valid: Cell<bool>,
|
||||
}
|
||||
|
||||
impl GPUCommandEncoder {
|
||||
pub fn new_inherited(
|
||||
channel: WebGPU,
|
||||
device: WebGPUDevice,
|
||||
device: &GPUDevice,
|
||||
encoder: webgpu::WebGPUCommandEncoder,
|
||||
valid: bool,
|
||||
label: Option<USVString>,
|
||||
|
@ -65,7 +65,7 @@ impl GPUCommandEncoder {
|
|||
channel,
|
||||
reflector_: Reflector::new(),
|
||||
label: DomRefCell::new(label),
|
||||
device,
|
||||
device: Dom::from_ref(device),
|
||||
encoder,
|
||||
buffers: DomRefCell::new(HashSet::new()),
|
||||
state: DomRefCell::new(GPUCommandEncoderState::Open),
|
||||
|
@ -76,7 +76,7 @@ impl GPUCommandEncoder {
|
|||
pub fn new(
|
||||
global: &GlobalScope,
|
||||
channel: WebGPU,
|
||||
device: WebGPUDevice,
|
||||
device: &GPUDevice,
|
||||
encoder: webgpu::WebGPUCommandEncoder,
|
||||
valid: bool,
|
||||
label: Option<USVString>,
|
||||
|
@ -370,6 +370,8 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder {
|
|||
.0
|
||||
.send(WebGPURequest::CommandEncoderFinish {
|
||||
command_encoder_id: self.encoder.0,
|
||||
device_id: self.device.id().0,
|
||||
scope_id: self.device.use_current_scope(),
|
||||
// TODO(zakorgy): We should use `_descriptor` here after it's not empty
|
||||
// and the underlying wgpu-core struct is serializable
|
||||
})
|
||||
|
|
|
@ -39,7 +39,7 @@ use crate::dom::bindings::codegen::UnionTypes::Uint32ArrayOrString;
|
|||
use crate::dom::bindings::error::Error;
|
||||
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject};
|
||||
use crate::dom::bindings::root::{Dom, DomRoot};
|
||||
use crate::dom::bindings::str::USVString;
|
||||
use crate::dom::bindings::str::{DOMString, USVString};
|
||||
use crate::dom::bindings::trace::RootedTraceableBox;
|
||||
use crate::dom::eventtarget::EventTarget;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
|
@ -49,6 +49,7 @@ use crate::dom::gpubindgrouplayout::GPUBindGroupLayout;
|
|||
use crate::dom::gpubuffer::{GPUBuffer, GPUBufferMapInfo, GPUBufferState};
|
||||
use crate::dom::gpucommandencoder::GPUCommandEncoder;
|
||||
use crate::dom::gpucomputepipeline::GPUComputePipeline;
|
||||
use crate::dom::gpuoutofmemoryerror::GPUOutOfMemoryError;
|
||||
use crate::dom::gpupipelinelayout::GPUPipelineLayout;
|
||||
use crate::dom::gpuqueue::GPUQueue;
|
||||
use crate::dom::gpurenderbundleencoder::GPURenderBundleEncoder;
|
||||
|
@ -56,6 +57,7 @@ use crate::dom::gpurenderpipeline::GPURenderPipeline;
|
|||
use crate::dom::gpusampler::GPUSampler;
|
||||
use crate::dom::gpushadermodule::GPUShaderModule;
|
||||
use crate::dom::gputexture::GPUTexture;
|
||||
use crate::dom::gpuvalidationerror::GPUValidationError;
|
||||
use crate::dom::promise::Promise;
|
||||
use crate::realms::InRealm;
|
||||
use crate::script_runtime::JSContext as SafeJSContext;
|
||||
|
@ -69,13 +71,12 @@ use std::rc::Rc;
|
|||
use webgpu::wgpu::{
|
||||
binding_model as wgpu_bind, command::RenderBundleEncoder, pipeline as wgpu_pipe,
|
||||
};
|
||||
use webgpu::{self, wgt, WebGPU, WebGPURequest};
|
||||
use webgpu::{self, identity::WebGPUOpResult, wgt, WebGPU, WebGPURequest};
|
||||
|
||||
type ErrorScopeId = u64;
|
||||
|
||||
#[derive(JSTraceable, MallocSizeOf)]
|
||||
struct ErrorScopeInfo {
|
||||
filter: GPUErrorFilter,
|
||||
op_count: u64,
|
||||
#[ignore_malloc_size_of = "defined in webgpu"]
|
||||
error: Option<GPUError>,
|
||||
|
@ -86,7 +87,7 @@ struct ErrorScopeInfo {
|
|||
#[derive(JSTraceable, MallocSizeOf)]
|
||||
struct ScopeContext {
|
||||
error_scopes: HashMap<ErrorScopeId, ErrorScopeInfo>,
|
||||
scope_stack: Vec<ErrorScopeId>,
|
||||
scope_stack: Vec<(ErrorScopeId, GPUErrorFilter)>,
|
||||
next_scope_id: ErrorScopeId,
|
||||
}
|
||||
|
||||
|
@ -106,9 +107,6 @@ pub struct GPUDevice {
|
|||
scope_context: DomRefCell<ScopeContext>,
|
||||
#[ignore_malloc_size_of = "promises are hard"]
|
||||
lost_promise: DomRefCell<Option<Rc<Promise>>>,
|
||||
#[ignore_malloc_size_of = "defined in webgpu"]
|
||||
bind_group_layouts:
|
||||
DomRefCell<HashMap<Vec<wgt::BindGroupLayoutEntry>, Dom<GPUBindGroupLayout>>>,
|
||||
}
|
||||
|
||||
impl GPUDevice {
|
||||
|
@ -136,7 +134,6 @@ impl GPUDevice {
|
|||
next_scope_id: 0,
|
||||
}),
|
||||
lost_promise: DomRefCell::new(None),
|
||||
bind_group_layouts: DomRefCell::new(HashMap::new()),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -165,18 +162,62 @@ impl GPUDevice {
|
|||
self.device
|
||||
}
|
||||
|
||||
pub fn handle_server_msg(&self, scope: ErrorScopeId, result: Result<(), GPUError>) {
|
||||
pub fn handle_server_msg(&self, scope: Option<ErrorScopeId>, result: WebGPUOpResult) {
|
||||
let result = match result {
|
||||
WebGPUOpResult::Success => Ok(()),
|
||||
WebGPUOpResult::ValidationError(m) => {
|
||||
let val_err = GPUValidationError::new(&self.global(), DOMString::from_string(m));
|
||||
Err((
|
||||
GPUError::GPUValidationError(val_err),
|
||||
GPUErrorFilter::Validation,
|
||||
))
|
||||
},
|
||||
WebGPUOpResult::OutOfMemoryError => {
|
||||
let oom_err = GPUOutOfMemoryError::new(&self.global());
|
||||
Err((
|
||||
GPUError::GPUOutOfMemoryError(oom_err),
|
||||
GPUErrorFilter::Out_of_memory,
|
||||
))
|
||||
},
|
||||
};
|
||||
|
||||
if let Some(s_id) = scope {
|
||||
if let Err((err, filter)) = result {
|
||||
let scop = self
|
||||
.scope_context
|
||||
.borrow()
|
||||
.scope_stack
|
||||
.iter()
|
||||
.rev()
|
||||
.find(|&&(id, fil)| id <= s_id && fil == filter)
|
||||
.map(|(id, _)| *id);
|
||||
if let Some(s) = scop {
|
||||
self.handle_error(s, err);
|
||||
} else {
|
||||
// Fire UncapturedErrorEvent.
|
||||
}
|
||||
}
|
||||
self.try_remove_scope(s_id);
|
||||
} else {
|
||||
// Fire UncapturedErrorEvent if result is Error
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_error(&self, scope: ErrorScopeId, error: GPUError) {
|
||||
let mut context = self.scope_context.borrow_mut();
|
||||
if let Some(mut err_scope) = context.error_scopes.get_mut(&scope) {
|
||||
if err_scope.error.is_none() {
|
||||
err_scope.error = Some(error);
|
||||
}
|
||||
} else {
|
||||
warn!("Could not find ErrorScope with Id({})", scope);
|
||||
}
|
||||
}
|
||||
|
||||
fn try_remove_scope(&self, scope: ErrorScopeId) {
|
||||
let mut context = self.scope_context.borrow_mut();
|
||||
let remove = if let Some(mut err_scope) = context.error_scopes.get_mut(&scope) {
|
||||
err_scope.op_count -= 1;
|
||||
match result {
|
||||
Ok(()) => {},
|
||||
Err(e) => {
|
||||
if err_scope.error.is_none() {
|
||||
err_scope.error = Some(e);
|
||||
}
|
||||
},
|
||||
}
|
||||
if let Some(ref promise) = err_scope.promise {
|
||||
if !promise.is_fulfilled() {
|
||||
if let Some(ref e) = err_scope.error {
|
||||
|
@ -191,18 +232,19 @@ impl GPUDevice {
|
|||
}
|
||||
err_scope.op_count == 0 && err_scope.promise.is_some()
|
||||
} else {
|
||||
warn!("Could not find ErrroScope with Id({})", scope);
|
||||
warn!("Could not find ErrorScope with Id({})", scope);
|
||||
false
|
||||
};
|
||||
if remove {
|
||||
let _ = context.error_scopes.remove(&scope);
|
||||
context.scope_stack.retain(|(id, _)| *id != scope);
|
||||
}
|
||||
}
|
||||
|
||||
fn use_current_scope(&self) -> Option<ErrorScopeId> {
|
||||
pub fn use_current_scope(&self) -> Option<ErrorScopeId> {
|
||||
let mut context = self.scope_context.borrow_mut();
|
||||
let scope_id = context.scope_stack.last().cloned();
|
||||
scope_id.and_then(|s_id| {
|
||||
let scope_id = context.scope_stack.last().copied();
|
||||
scope_id.and_then(|(s_id, _)| {
|
||||
context.error_scopes.get_mut(&s_id).map(|mut scope| {
|
||||
scope.op_count += 1;
|
||||
s_id
|
||||
|
@ -265,10 +307,13 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
.wgpu_id_hub()
|
||||
.lock()
|
||||
.create_buffer_id(self.device.0.backend());
|
||||
|
||||
let scope_id = self.use_current_scope();
|
||||
self.channel
|
||||
.0
|
||||
.send(WebGPURequest::CreateBuffer {
|
||||
device_id: self.device.0,
|
||||
scope_id,
|
||||
buffer_id: id,
|
||||
descriptor: wgpu_descriptor,
|
||||
})
|
||||
|
@ -388,28 +433,13 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
|
||||
let scope_id = self.use_current_scope();
|
||||
|
||||
// Check for equivalent GPUBindGroupLayout
|
||||
{
|
||||
let layout = self
|
||||
.bind_group_layouts
|
||||
.borrow()
|
||||
.get(&entries)
|
||||
.map(|bgl| DomRoot::from_ref(&**bgl));
|
||||
if let Some(l) = layout {
|
||||
if let Some(i) = scope_id {
|
||||
self.handle_server_msg(i, Ok(()));
|
||||
}
|
||||
return l;
|
||||
}
|
||||
}
|
||||
|
||||
let desc = wgt::BindGroupLayoutDescriptor {
|
||||
label: descriptor
|
||||
.parent
|
||||
.label
|
||||
.as_ref()
|
||||
.map(|s| Cow::Owned(s.to_string())),
|
||||
entries: Cow::Owned(entries.clone()),
|
||||
entries: Cow::Owned(entries),
|
||||
};
|
||||
|
||||
let bind_group_layout_id = self
|
||||
|
@ -429,17 +459,11 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
|
||||
let bgl = webgpu::WebGPUBindGroupLayout(bind_group_layout_id);
|
||||
|
||||
let layout = GPUBindGroupLayout::new(
|
||||
GPUBindGroupLayout::new(
|
||||
&self.global(),
|
||||
bgl,
|
||||
descriptor.parent.label.as_ref().cloned(),
|
||||
);
|
||||
|
||||
self.bind_group_layouts
|
||||
.borrow_mut()
|
||||
.insert(entries, Dom::from_ref(&*layout));
|
||||
|
||||
layout
|
||||
)
|
||||
}
|
||||
|
||||
/// https://gpuweb.github.io/gpuweb/#dom-gpudevice-createpipelinelayout
|
||||
|
@ -562,10 +586,13 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
.wgpu_id_hub()
|
||||
.lock()
|
||||
.create_shader_module_id(self.device.0.backend());
|
||||
|
||||
let scope_id = self.use_current_scope();
|
||||
self.channel
|
||||
.0
|
||||
.send(WebGPURequest::CreateShaderModule {
|
||||
device_id: self.device.0,
|
||||
scope_id,
|
||||
program_id,
|
||||
program,
|
||||
})
|
||||
|
@ -628,10 +655,12 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
.wgpu_id_hub()
|
||||
.lock()
|
||||
.create_command_encoder_id(self.device.0.backend());
|
||||
let scope_id = self.use_current_scope();
|
||||
self.channel
|
||||
.0
|
||||
.send(WebGPURequest::CreateCommandEncoder {
|
||||
device_id: self.device.0,
|
||||
scope_id,
|
||||
command_encoder_id,
|
||||
label: descriptor.parent.label.as_ref().map(|s| s.to_string()),
|
||||
})
|
||||
|
@ -642,7 +671,7 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
GPUCommandEncoder::new(
|
||||
&self.global(),
|
||||
self.channel.clone(),
|
||||
self.device,
|
||||
&self,
|
||||
encoder,
|
||||
true,
|
||||
descriptor.parent.label.as_ref().cloned(),
|
||||
|
@ -675,12 +704,15 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
.lock()
|
||||
.create_texture_id(self.device.0.backend());
|
||||
|
||||
let scope_id = self.use_current_scope();
|
||||
|
||||
self.channel
|
||||
.0
|
||||
.send(WebGPURequest::CreateTexture {
|
||||
device_id: self.device.0,
|
||||
texture_id,
|
||||
descriptor: desc,
|
||||
scope_id,
|
||||
})
|
||||
.expect("Failed to create WebGPU Texture");
|
||||
|
||||
|
@ -689,7 +721,7 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
GPUTexture::new(
|
||||
&self.global(),
|
||||
texture,
|
||||
self.device,
|
||||
&self,
|
||||
self.channel.clone(),
|
||||
size,
|
||||
descriptor.mipLevelCount,
|
||||
|
@ -723,10 +755,13 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
anisotropy_clamp: None,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let scope_id = self.use_current_scope();
|
||||
self.channel
|
||||
.0
|
||||
.send(WebGPURequest::CreateSampler {
|
||||
device_id: self.device.0,
|
||||
scope_id,
|
||||
sampler_id,
|
||||
descriptor: desc,
|
||||
})
|
||||
|
@ -914,7 +949,7 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
GPURenderBundleEncoder::new(
|
||||
&self.global(),
|
||||
render_bundle_encoder,
|
||||
self.device,
|
||||
&self,
|
||||
self.channel.clone(),
|
||||
descriptor.parent.label.as_ref().cloned(),
|
||||
)
|
||||
|
@ -926,13 +961,12 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
let scope_id = context.next_scope_id;
|
||||
context.next_scope_id += 1;
|
||||
let err_scope = ErrorScopeInfo {
|
||||
filter,
|
||||
op_count: 0,
|
||||
error: None,
|
||||
promise: None,
|
||||
};
|
||||
let res = context.error_scopes.insert(scope_id, err_scope);
|
||||
context.scope_stack.push(scope_id);
|
||||
context.scope_stack.push((scope_id, filter));
|
||||
assert!(res.is_none());
|
||||
}
|
||||
|
||||
|
@ -940,8 +974,8 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
fn PopErrorScope(&self, comp: InRealm) -> Rc<Promise> {
|
||||
let mut context = self.scope_context.borrow_mut();
|
||||
let promise = Promise::new_in_current_realm(&self.global(), comp);
|
||||
let scope_id = if let Some(e) = context.scope_stack.pop() {
|
||||
e
|
||||
let scope_id = if let Some((e, _)) = context.scope_stack.last() {
|
||||
*e
|
||||
} else {
|
||||
promise.reject_error(Error::Operation);
|
||||
return promise;
|
||||
|
@ -963,6 +997,7 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
};
|
||||
if remove {
|
||||
let _ = context.error_scopes.remove(&scope_id);
|
||||
let _ = context.scope_stack.pop();
|
||||
}
|
||||
promise
|
||||
}
|
||||
|
|
|
@ -6,17 +6,18 @@ use crate::dom::bindings::cell::DomRefCell;
|
|||
use crate::dom::bindings::codegen::Bindings::GPURenderBundleBinding::GPURenderBundleDescriptor;
|
||||
use crate::dom::bindings::codegen::Bindings::GPURenderBundleEncoderBinding::GPURenderBundleEncoderMethods;
|
||||
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
|
||||
use crate::dom::bindings::root::DomRoot;
|
||||
use crate::dom::bindings::root::{Dom, DomRoot};
|
||||
use crate::dom::bindings::str::USVString;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::gpubindgroup::GPUBindGroup;
|
||||
use crate::dom::gpubuffer::GPUBuffer;
|
||||
use crate::dom::gpudevice::GPUDevice;
|
||||
use crate::dom::gpurenderbundle::GPURenderBundle;
|
||||
use crate::dom::gpurenderpipeline::GPURenderPipeline;
|
||||
use dom_struct::dom_struct;
|
||||
use webgpu::{
|
||||
wgpu::command::{bundle_ffi as wgpu_bundle, RenderBundleEncoder},
|
||||
wgt, WebGPU, WebGPUDevice, WebGPURenderBundle, WebGPURequest,
|
||||
wgt, WebGPU, WebGPURenderBundle, WebGPURequest,
|
||||
};
|
||||
|
||||
#[dom_struct]
|
||||
|
@ -24,7 +25,7 @@ pub struct GPURenderBundleEncoder {
|
|||
reflector_: Reflector,
|
||||
#[ignore_malloc_size_of = "channels are hard"]
|
||||
channel: WebGPU,
|
||||
device: WebGPUDevice,
|
||||
device: Dom<GPUDevice>,
|
||||
#[ignore_malloc_size_of = "defined in wgpu-core"]
|
||||
render_bundle_encoder: DomRefCell<Option<RenderBundleEncoder>>,
|
||||
label: DomRefCell<Option<USVString>>,
|
||||
|
@ -33,14 +34,14 @@ pub struct GPURenderBundleEncoder {
|
|||
impl GPURenderBundleEncoder {
|
||||
fn new_inherited(
|
||||
render_bundle_encoder: RenderBundleEncoder,
|
||||
device: WebGPUDevice,
|
||||
device: &GPUDevice,
|
||||
channel: WebGPU,
|
||||
label: Option<USVString>,
|
||||
) -> Self {
|
||||
Self {
|
||||
reflector_: Reflector::new(),
|
||||
render_bundle_encoder: DomRefCell::new(Some(render_bundle_encoder)),
|
||||
device,
|
||||
device: Dom::from_ref(device),
|
||||
channel,
|
||||
label: DomRefCell::new(label),
|
||||
}
|
||||
|
@ -49,7 +50,7 @@ impl GPURenderBundleEncoder {
|
|||
pub fn new(
|
||||
global: &GlobalScope,
|
||||
render_bundle_encoder: RenderBundleEncoder,
|
||||
device: WebGPUDevice,
|
||||
device: &GPUDevice,
|
||||
channel: WebGPU,
|
||||
label: Option<USVString>,
|
||||
) -> DomRoot<Self> {
|
||||
|
@ -190,7 +191,7 @@ impl GPURenderBundleEncoderMethods for GPURenderBundleEncoder {
|
|||
.global()
|
||||
.wgpu_id_hub()
|
||||
.lock()
|
||||
.create_render_bundle_id(self.device.0.backend());
|
||||
.create_render_bundle_id(self.device.id().0.backend());
|
||||
|
||||
self.channel
|
||||
.0
|
||||
|
@ -198,6 +199,8 @@ impl GPURenderBundleEncoderMethods for GPURenderBundleEncoder {
|
|||
render_bundle_encoder: encoder,
|
||||
descriptor: desc,
|
||||
render_bundle_id,
|
||||
device_id: self.device.id().0,
|
||||
scope_id: self.device.use_current_scope(),
|
||||
})
|
||||
.expect("Failed to send RenderBundleEncoderFinish");
|
||||
|
||||
|
@ -205,7 +208,7 @@ impl GPURenderBundleEncoderMethods for GPURenderBundleEncoder {
|
|||
GPURenderBundle::new(
|
||||
&self.global(),
|
||||
render_bundle,
|
||||
self.device,
|
||||
self.device.id(),
|
||||
self.channel.clone(),
|
||||
descriptor.parent.label.as_ref().cloned(),
|
||||
)
|
||||
|
|
|
@ -10,21 +10,21 @@ use crate::dom::bindings::codegen::Bindings::GPUTextureViewBinding::{
|
|||
GPUTextureAspect, GPUTextureViewDescriptor, GPUTextureViewDimension,
|
||||
};
|
||||
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
|
||||
use crate::dom::bindings::root::DomRoot;
|
||||
use crate::dom::bindings::root::{Dom, DomRoot};
|
||||
use crate::dom::bindings::str::USVString;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::gpudevice::{convert_texture_format, convert_texture_view_dimension};
|
||||
use crate::dom::gpudevice::{convert_texture_format, convert_texture_view_dimension, GPUDevice};
|
||||
use crate::dom::gputextureview::GPUTextureView;
|
||||
use dom_struct::dom_struct;
|
||||
use std::string::String;
|
||||
use webgpu::{wgt, WebGPU, WebGPUDevice, WebGPURequest, WebGPUTexture, WebGPUTextureView};
|
||||
use webgpu::{wgt, WebGPU, WebGPURequest, WebGPUTexture, WebGPUTextureView};
|
||||
|
||||
#[dom_struct]
|
||||
pub struct GPUTexture {
|
||||
reflector_: Reflector,
|
||||
texture: WebGPUTexture,
|
||||
label: DomRefCell<Option<USVString>>,
|
||||
device: WebGPUDevice,
|
||||
device: Dom<GPUDevice>,
|
||||
#[ignore_malloc_size_of = "channels are hard"]
|
||||
channel: WebGPU,
|
||||
#[ignore_malloc_size_of = "defined in webgpu"]
|
||||
|
@ -39,7 +39,7 @@ pub struct GPUTexture {
|
|||
impl GPUTexture {
|
||||
fn new_inherited(
|
||||
texture: WebGPUTexture,
|
||||
device: WebGPUDevice,
|
||||
device: &GPUDevice,
|
||||
channel: WebGPU,
|
||||
texture_size: GPUExtent3DDict,
|
||||
mip_level_count: u32,
|
||||
|
@ -53,7 +53,7 @@ impl GPUTexture {
|
|||
reflector_: Reflector::new(),
|
||||
texture,
|
||||
label: DomRefCell::new(label),
|
||||
device,
|
||||
device: Dom::from_ref(device),
|
||||
channel,
|
||||
texture_size,
|
||||
mip_level_count,
|
||||
|
@ -67,7 +67,7 @@ impl GPUTexture {
|
|||
pub fn new(
|
||||
global: &GlobalScope,
|
||||
texture: WebGPUTexture,
|
||||
device: WebGPUDevice,
|
||||
device: &GPUDevice,
|
||||
channel: WebGPU,
|
||||
texture_size: GPUExtent3DDict,
|
||||
mip_level_count: u32,
|
||||
|
@ -126,7 +126,7 @@ impl GPUTextureMethods for GPUTexture {
|
|||
match self.dimension {
|
||||
GPUTextureDimension::_1d => GPUTextureViewDimension::_1d,
|
||||
GPUTextureDimension::_2d => {
|
||||
if self.texture_size.depth > 1 && descriptor.arrayLayerCount == 0 {
|
||||
if self.texture_size.depth > 1 && descriptor.arrayLayerCount.is_none() {
|
||||
GPUTextureViewDimension::_2d_array
|
||||
} else {
|
||||
GPUTextureViewDimension::_2d
|
||||
|
@ -152,31 +152,27 @@ impl GPUTextureMethods for GPUTexture {
|
|||
GPUTextureAspect::Depth_only => wgt::TextureAspect::DepthOnly,
|
||||
},
|
||||
base_mip_level: descriptor.baseMipLevel,
|
||||
level_count: if descriptor.mipLevelCount == 0 {
|
||||
self.mip_level_count - descriptor.baseMipLevel
|
||||
} else {
|
||||
descriptor.mipLevelCount
|
||||
},
|
||||
level_count: descriptor.mipLevelCount.as_ref().copied(),
|
||||
base_array_layer: descriptor.baseArrayLayer,
|
||||
array_layer_count: if descriptor.arrayLayerCount == 0 {
|
||||
self.texture_size.depth - descriptor.baseArrayLayer
|
||||
} else {
|
||||
descriptor.arrayLayerCount
|
||||
},
|
||||
array_layer_count: descriptor.arrayLayerCount.as_ref().copied(),
|
||||
};
|
||||
|
||||
let texture_view_id = self
|
||||
.global()
|
||||
.wgpu_id_hub()
|
||||
.lock()
|
||||
.create_texture_view_id(self.device.0.backend());
|
||||
.create_texture_view_id(self.device.id().0.backend());
|
||||
|
||||
let scope_id = self.device.use_current_scope();
|
||||
|
||||
self.channel
|
||||
.0
|
||||
.send(WebGPURequest::CreateTextureView {
|
||||
texture_id: self.texture.0,
|
||||
texture_view_id,
|
||||
device_id: self.device.id().0,
|
||||
descriptor: desc,
|
||||
scope_id,
|
||||
})
|
||||
.expect("Failed to create WebGPU texture view");
|
||||
|
||||
|
|
|
@ -13,9 +13,9 @@ dictionary GPUTextureViewDescriptor : GPUObjectDescriptorBase {
|
|||
GPUTextureViewDimension dimension;
|
||||
GPUTextureAspect aspect = "all";
|
||||
GPUIntegerCoordinate baseMipLevel = 0;
|
||||
GPUIntegerCoordinate mipLevelCount = 0;
|
||||
GPUIntegerCoordinate mipLevelCount;
|
||||
GPUIntegerCoordinate baseArrayLayer = 0;
|
||||
GPUIntegerCoordinate arrayLayerCount = 0;
|
||||
GPUIntegerCoordinate arrayLayerCount;
|
||||
};
|
||||
|
||||
enum GPUTextureViewDimension {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue