Prevent redundant texture and buffer destroy calls

This commit is contained in:
Kunal Mohan 2020-08-24 16:04:34 +05:30
parent 84185eb1da
commit 851f83c61f
4 changed files with 15 additions and 9 deletions

4
Cargo.lock generated
View file

@ -7028,7 +7028,7 @@ dependencies = [
[[package]] [[package]]
name = "wgpu-core" name = "wgpu-core"
version = "0.6.0" version = "0.6.0"
source = "git+https://github.com/gfx-rs/wgpu#1d0e0ce37ede5ec53000ab252c27b8cf856865b2" source = "git+https://github.com/gfx-rs/wgpu#59f0996eabd43e882d4bfc73ee5b4ed912617abf"
dependencies = [ dependencies = [
"arrayvec 0.5.1", "arrayvec 0.5.1",
"bitflags", "bitflags",
@ -7055,7 +7055,7 @@ dependencies = [
[[package]] [[package]]
name = "wgpu-types" name = "wgpu-types"
version = "0.6.0" version = "0.6.0"
source = "git+https://github.com/gfx-rs/wgpu#1d0e0ce37ede5ec53000ab252c27b8cf856865b2" source = "git+https://github.com/gfx-rs/wgpu#59f0996eabd43e882d4bfc73ee5b4ed912617abf"
dependencies = [ dependencies = [
"bitflags", "bitflags",
"serde", "serde",

View file

@ -184,6 +184,7 @@ impl GPUBufferMethods for GPUBuffer {
GPUBufferState::Mapped | GPUBufferState::MappedAtCreation => { GPUBufferState::Mapped | GPUBufferState::MappedAtCreation => {
self.Unmap(); self.Unmap();
}, },
GPUBufferState::Destroyed => return,
_ => {}, _ => {},
}; };
if let Err(e) = self if let Err(e) = self

View file

@ -18,6 +18,7 @@ use crate::dom::gpudevice::{
}; };
use crate::dom::gputextureview::GPUTextureView; use crate::dom::gputextureview::GPUTextureView;
use dom_struct::dom_struct; use dom_struct::dom_struct;
use std::cell::Cell;
use std::num::NonZeroU32; use std::num::NonZeroU32;
use std::string::String; use std::string::String;
use webgpu::{ use webgpu::{
@ -40,6 +41,7 @@ pub struct GPUTexture {
dimension: GPUTextureDimension, dimension: GPUTextureDimension,
format: GPUTextureFormat, format: GPUTextureFormat,
texture_usage: u32, texture_usage: u32,
destroyed: Cell<bool>,
} }
impl GPUTexture { impl GPUTexture {
@ -67,6 +69,7 @@ impl GPUTexture {
dimension, dimension,
format, format,
texture_usage, texture_usage,
destroyed: Cell::new(false),
} }
} }
@ -197,6 +200,9 @@ impl GPUTextureMethods for GPUTexture {
/// https://gpuweb.github.io/gpuweb/#dom-gputexture-destroy /// https://gpuweb.github.io/gpuweb/#dom-gputexture-destroy
fn Destroy(&self) { fn Destroy(&self) {
if self.destroyed.get() {
return;
}
if let Err(e) = self if let Err(e) = self
.channel .channel
.0 .0
@ -207,5 +213,6 @@ impl GPUTextureMethods for GPUTexture {
self.texture.0, e self.texture.0, e
); );
}; };
self.destroyed.set(true);
} }
} }

View file

@ -21,7 +21,6 @@ use servo_config::pref;
use smallvec::SmallVec; use smallvec::SmallVec;
use std::borrow::Cow; use std::borrow::Cow;
use std::cell::RefCell; use std::cell::RefCell;
use std::collections::hash_map::Entry;
use std::collections::HashMap; use std::collections::HashMap;
use std::num::NonZeroU64; use std::num::NonZeroU64;
use std::rc::Rc; use std::rc::Rc;
@ -475,9 +474,7 @@ impl<'a> WGPU<'a> {
)) ))
.map_err(|e| format!("{:?}", e)) .map_err(|e| format!("{:?}", e))
}; };
if result.is_err() {
self.encoder_record_error(command_encoder_id, result.clone()); self.encoder_record_error(command_encoder_id, result.clone());
}
self.send_result(device_id, scope_id, result); self.send_result(device_id, scope_id, result);
}, },
WebGPURequest::CopyBufferToBuffer { WebGPURequest::CopyBufferToBuffer {
@ -1282,9 +1279,10 @@ impl<'a> WGPU<'a> {
result: Result<U, T>, result: Result<U, T>,
) { ) {
if let Err(e) = result { if let Err(e) = result {
if let Entry::Vacant(v) = self.error_command_encoders.borrow_mut().entry(encoder_id) { self.error_command_encoders
v.insert(format!("{:?}", e)); .borrow_mut()
} .entry(encoder_id)
.or_insert_with(|| format!("{:?}", e));
} }
} }
} }