mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
webgpu: Move actual Create* implementations from GPUDevice
to Self (#33320)
* Move actual Create* implementations from `GPUDevice` to Self Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> * move Create*Pipeline to Self::create Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> * `parse_render_pipeline` outside`GPURenderPipeline::create` 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
312cf0df08
commit
ebed9218f2
14 changed files with 594 additions and 486 deletions
|
@ -14,14 +14,15 @@ use webgpu::{wgt, Mapping, WebGPU, WebGPUBuffer, WebGPURequest, WebGPUResponse};
|
|||
|
||||
use super::bindings::buffer_source::DataBlock;
|
||||
use super::bindings::codegen::Bindings::WebGPUBinding::{
|
||||
GPUBufferMapState, GPUFlagsConstant, GPUMapModeFlags,
|
||||
GPUBufferDescriptor, GPUBufferMapState, GPUFlagsConstant, GPUMapModeFlags,
|
||||
};
|
||||
use super::gpuconvert::convert_label;
|
||||
use crate::dom::bindings::cell::DomRefCell;
|
||||
use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{
|
||||
GPUBufferMethods, GPUMapModeConstants, GPUSize64,
|
||||
};
|
||||
use crate::dom::bindings::error::{Error, Fallible};
|
||||
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
|
||||
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
|
||||
use crate::dom::bindings::root::{Dom, DomRoot};
|
||||
use crate::dom::bindings::str::USVString;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
|
@ -130,6 +131,54 @@ impl GPUBuffer {
|
|||
pub fn id(&self) -> WebGPUBuffer {
|
||||
self.buffer
|
||||
}
|
||||
|
||||
/// <https://gpuweb.github.io/gpuweb/#dom-gpudevice-createbuffer>
|
||||
pub fn create(
|
||||
device: &GPUDevice,
|
||||
descriptor: &GPUBufferDescriptor,
|
||||
) -> Fallible<DomRoot<GPUBuffer>> {
|
||||
let desc = wgt::BufferDescriptor {
|
||||
label: convert_label(&descriptor.parent),
|
||||
size: descriptor.size as wgt::BufferAddress,
|
||||
usage: wgt::BufferUsages::from_bits_retain(descriptor.usage),
|
||||
mapped_at_creation: descriptor.mappedAtCreation,
|
||||
};
|
||||
let id = device
|
||||
.global()
|
||||
.wgpu_id_hub()
|
||||
.create_buffer_id(device.id().0.backend());
|
||||
|
||||
device
|
||||
.channel()
|
||||
.0
|
||||
.send(WebGPURequest::CreateBuffer {
|
||||
device_id: device.id().0,
|
||||
buffer_id: id,
|
||||
descriptor: desc,
|
||||
})
|
||||
.expect("Failed to create WebGPU buffer");
|
||||
|
||||
let buffer = WebGPUBuffer(id);
|
||||
let mapping = if descriptor.mappedAtCreation {
|
||||
Some(ActiveBufferMapping::new(
|
||||
GPUMapModeConstants::WRITE,
|
||||
0..descriptor.size,
|
||||
)?)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
Ok(GPUBuffer::new(
|
||||
&device.global(),
|
||||
device.channel().clone(),
|
||||
buffer,
|
||||
device,
|
||||
descriptor.size,
|
||||
descriptor.usage,
|
||||
mapping,
|
||||
descriptor.parent.label.clone(),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for GPUBuffer {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue