mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
webgpu: Sync GPUBuffer
(#33154)
* More helpers on `Promise` Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> * Sync `GPUBuffer` Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> * Set some good expectations Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> * Some bad expect also on firefox Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> * Extract DataBlock, DataView impl from GPUBuffer Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> * Fix size check to work on 32bit platforms Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> --------- Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
parent
bb5926b329
commit
7fce24f9d5
12 changed files with 690 additions and 1163 deletions
|
@ -9,7 +9,6 @@ use std::cell::Cell;
|
|||
use std::collections::HashMap;
|
||||
use std::num::NonZeroU64;
|
||||
use std::rc::Rc;
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use dom_struct::dom_struct;
|
||||
use js::jsapi::{Heap, JSObject};
|
||||
|
@ -24,7 +23,9 @@ use webgpu::{
|
|||
WebGPUResponse,
|
||||
};
|
||||
|
||||
use super::bindings::codegen::Bindings::WebGPUBinding::{GPUPipelineErrorReason, GPUTextureFormat};
|
||||
use super::bindings::codegen::Bindings::WebGPUBinding::{
|
||||
GPUMapModeConstants, GPUPipelineErrorReason, GPUTextureFormat,
|
||||
};
|
||||
use super::bindings::codegen::UnionTypes::GPUPipelineLayoutOrGPUAutoLayoutMode;
|
||||
use super::bindings::error::Fallible;
|
||||
use super::gpu::AsyncWGPUListener;
|
||||
|
@ -55,7 +56,7 @@ use crate::dom::gpu::response_async;
|
|||
use crate::dom::gpuadapter::GPUAdapter;
|
||||
use crate::dom::gpubindgroup::GPUBindGroup;
|
||||
use crate::dom::gpubindgrouplayout::GPUBindGroupLayout;
|
||||
use crate::dom::gpubuffer::{GPUBuffer, GPUBufferMapInfo, GPUBufferState};
|
||||
use crate::dom::gpubuffer::{ActiveBufferMapping, GPUBuffer};
|
||||
use crate::dom::gpucommandencoder::GPUCommandEncoder;
|
||||
use crate::dom::gpucomputepipeline::GPUComputePipeline;
|
||||
use crate::dom::gpuconvert::{
|
||||
|
@ -213,6 +214,10 @@ impl GPUDevice {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn is_lost(&self) -> bool {
|
||||
self.lost_promise.borrow().is_fulfilled()
|
||||
}
|
||||
|
||||
fn get_pipeline_layout_data(
|
||||
&self,
|
||||
layout: &GPUPipelineLayoutOrGPUAutoLayoutMode,
|
||||
|
@ -452,31 +457,23 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
.expect("Failed to create WebGPU buffer");
|
||||
|
||||
let buffer = webgpu::WebGPUBuffer(id);
|
||||
let map_info;
|
||||
let state;
|
||||
if descriptor.mappedAtCreation {
|
||||
let buf_data = vec![0u8; descriptor.size as usize];
|
||||
map_info = DomRefCell::new(Some(GPUBufferMapInfo {
|
||||
mapping: Arc::new(Mutex::new(buf_data)),
|
||||
mapping_range: 0..descriptor.size,
|
||||
mapped_ranges: Vec::new(),
|
||||
js_buffers: Vec::new(),
|
||||
map_mode: None,
|
||||
}));
|
||||
state = GPUBufferState::MappedAtCreation;
|
||||
let mapping = if descriptor.mappedAtCreation {
|
||||
Some(ActiveBufferMapping::new(
|
||||
GPUMapModeConstants::WRITE,
|
||||
0..descriptor.size,
|
||||
)?)
|
||||
} else {
|
||||
map_info = DomRefCell::new(None);
|
||||
state = GPUBufferState::Unmapped;
|
||||
}
|
||||
None
|
||||
};
|
||||
|
||||
Ok(GPUBuffer::new(
|
||||
&self.global(),
|
||||
self.channel.clone(),
|
||||
buffer,
|
||||
self,
|
||||
state,
|
||||
descriptor.size,
|
||||
map_info,
|
||||
descriptor.usage,
|
||||
mapping,
|
||||
descriptor.parent.label.clone(),
|
||||
))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue