mirror of
https://github.com/servo/servo.git
synced 2025-07-25 08:10:21 +01:00
Validate copybuffertobuffer() + some spec update
The spec update includes renaming bindings to entries and adding CommandEncoderState.
This commit is contained in:
parent
e1cc38bea8
commit
1aeae47299
11 changed files with 136 additions and 45 deletions
|
@ -37,6 +37,7 @@ use crate::dom::bindings::root::{Dom, DomRoot};
|
||||||
use crate::dom::bindings::str::{DOMString, USVString};
|
use crate::dom::bindings::str::{DOMString, USVString};
|
||||||
use crate::dom::bindings::utils::WindowProxyHandler;
|
use crate::dom::bindings::utils::WindowProxyHandler;
|
||||||
use crate::dom::gpubuffer::GPUBufferState;
|
use crate::dom::gpubuffer::GPUBufferState;
|
||||||
|
use crate::dom::gpucommandencoder::GPUCommandEncoderState;
|
||||||
use crate::dom::htmlimageelement::SourceSet;
|
use crate::dom::htmlimageelement::SourceSet;
|
||||||
use crate::dom::htmlmediaelement::{HTMLMediaElementFetchContext, MediaFrameRenderer};
|
use crate::dom::htmlmediaelement::{HTMLMediaElementFetchContext, MediaFrameRenderer};
|
||||||
use crate::dom::identityhub::Identities;
|
use crate::dom::identityhub::Identities;
|
||||||
|
@ -559,6 +560,7 @@ unsafe_no_jsmanaged_fields!(WebGPUCommandEncoder);
|
||||||
unsafe_no_jsmanaged_fields!(WebGPUDevice);
|
unsafe_no_jsmanaged_fields!(WebGPUDevice);
|
||||||
unsafe_no_jsmanaged_fields!(Option<RawPass>);
|
unsafe_no_jsmanaged_fields!(Option<RawPass>);
|
||||||
unsafe_no_jsmanaged_fields!(GPUBufferState);
|
unsafe_no_jsmanaged_fields!(GPUBufferState);
|
||||||
|
unsafe_no_jsmanaged_fields!(GPUCommandEncoderState);
|
||||||
unsafe_no_jsmanaged_fields!(WebXRSwapChainId);
|
unsafe_no_jsmanaged_fields!(WebXRSwapChainId);
|
||||||
unsafe_no_jsmanaged_fields!(MediaList);
|
unsafe_no_jsmanaged_fields!(MediaList);
|
||||||
unsafe_no_jsmanaged_fields!(
|
unsafe_no_jsmanaged_fields!(
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
use crate::dom::bindings::cell::DomRefCell;
|
use crate::dom::bindings::cell::DomRefCell;
|
||||||
use crate::dom::bindings::codegen::Bindings::GPUBindGroupLayoutBinding::{
|
use crate::dom::bindings::codegen::Bindings::GPUBindGroupLayoutBinding::{
|
||||||
GPUBindGroupLayoutBindings, GPUBindGroupLayoutMethods,
|
GPUBindGroupLayoutEntry, GPUBindGroupLayoutMethods,
|
||||||
};
|
};
|
||||||
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
|
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
|
||||||
use crate::dom::bindings::root::DomRoot;
|
use crate::dom::bindings::root::DomRoot;
|
||||||
|
@ -20,7 +20,7 @@ pub struct GPUBindGroupLayout {
|
||||||
label: DomRefCell<Option<DOMString>>,
|
label: DomRefCell<Option<DOMString>>,
|
||||||
bind_group_layout: WebGPUBindGroupLayout,
|
bind_group_layout: WebGPUBindGroupLayout,
|
||||||
#[ignore_malloc_size_of = "defined in webgpu"]
|
#[ignore_malloc_size_of = "defined in webgpu"]
|
||||||
bindings: Vec<GPUBindGroupLayoutBindings>,
|
bindings: Vec<GPUBindGroupLayoutEntry>,
|
||||||
#[ignore_malloc_size_of = "defined in webgpu"]
|
#[ignore_malloc_size_of = "defined in webgpu"]
|
||||||
channel: WebGPU,
|
channel: WebGPU,
|
||||||
valid: Cell<bool>,
|
valid: Cell<bool>,
|
||||||
|
@ -30,7 +30,7 @@ impl GPUBindGroupLayout {
|
||||||
fn new_inherited(
|
fn new_inherited(
|
||||||
channel: WebGPU,
|
channel: WebGPU,
|
||||||
bind_group_layout: WebGPUBindGroupLayout,
|
bind_group_layout: WebGPUBindGroupLayout,
|
||||||
bindings: Vec<GPUBindGroupLayoutBindings>,
|
bindings: Vec<GPUBindGroupLayoutEntry>,
|
||||||
valid: bool,
|
valid: bool,
|
||||||
) -> GPUBindGroupLayout {
|
) -> GPUBindGroupLayout {
|
||||||
Self {
|
Self {
|
||||||
|
@ -47,7 +47,7 @@ impl GPUBindGroupLayout {
|
||||||
global: &GlobalScope,
|
global: &GlobalScope,
|
||||||
channel: WebGPU,
|
channel: WebGPU,
|
||||||
bind_group_layout: WebGPUBindGroupLayout,
|
bind_group_layout: WebGPUBindGroupLayout,
|
||||||
bindings: Vec<GPUBindGroupLayoutBindings>,
|
bindings: Vec<GPUBindGroupLayoutEntry>,
|
||||||
valid: bool,
|
valid: bool,
|
||||||
) -> DomRoot<GPUBindGroupLayout> {
|
) -> DomRoot<GPUBindGroupLayout> {
|
||||||
reflect_dom_object(
|
reflect_dom_object(
|
||||||
|
@ -71,7 +71,7 @@ impl GPUBindGroupLayout {
|
||||||
self.bind_group_layout
|
self.bind_group_layout
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bindings(&self) -> &[GPUBindGroupLayoutBindings] {
|
pub fn bindings(&self) -> &[GPUBindGroupLayoutEntry] {
|
||||||
&self.bindings
|
&self.bindings
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use crate::dom::bindings::cell::{DomRefCell, Ref};
|
use crate::dom::bindings::cell::{DomRefCell, Ref};
|
||||||
use crate::dom::bindings::codegen::Bindings::GPUBufferBinding::{GPUBufferMethods, GPUBufferSize};
|
use crate::dom::bindings::codegen::Bindings::GPUBufferBinding::{GPUBufferMethods, GPUSize64};
|
||||||
use crate::dom::bindings::error::Error;
|
use crate::dom::bindings::error::Error;
|
||||||
use crate::dom::bindings::reflector::DomObject;
|
use crate::dom::bindings::reflector::DomObject;
|
||||||
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
|
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
|
||||||
|
@ -44,7 +44,7 @@ pub struct GPUBuffer {
|
||||||
#[ignore_malloc_size_of = "defined in webgpu"]
|
#[ignore_malloc_size_of = "defined in webgpu"]
|
||||||
channel: WebGPU,
|
channel: WebGPU,
|
||||||
label: DomRefCell<Option<DOMString>>,
|
label: DomRefCell<Option<DOMString>>,
|
||||||
size: GPUBufferSize,
|
size: GPUSize64,
|
||||||
usage: u32,
|
usage: u32,
|
||||||
state: DomRefCell<GPUBufferState>,
|
state: DomRefCell<GPUBufferState>,
|
||||||
buffer: WebGPUBuffer,
|
buffer: WebGPUBuffer,
|
||||||
|
@ -60,7 +60,7 @@ impl GPUBuffer {
|
||||||
buffer: WebGPUBuffer,
|
buffer: WebGPUBuffer,
|
||||||
device: WebGPUDevice,
|
device: WebGPUDevice,
|
||||||
state: GPUBufferState,
|
state: GPUBufferState,
|
||||||
size: GPUBufferSize,
|
size: GPUSize64,
|
||||||
usage: u32,
|
usage: u32,
|
||||||
valid: bool,
|
valid: bool,
|
||||||
mapping: RootedTraceableBox<Heap<*mut JSObject>>,
|
mapping: RootedTraceableBox<Heap<*mut JSObject>>,
|
||||||
|
@ -86,7 +86,7 @@ impl GPUBuffer {
|
||||||
buffer: WebGPUBuffer,
|
buffer: WebGPUBuffer,
|
||||||
device: WebGPUDevice,
|
device: WebGPUDevice,
|
||||||
state: GPUBufferState,
|
state: GPUBufferState,
|
||||||
size: GPUBufferSize,
|
size: GPUSize64,
|
||||||
usage: u32,
|
usage: u32,
|
||||||
valid: bool,
|
valid: bool,
|
||||||
mapping: RootedTraceableBox<Heap<*mut JSObject>>,
|
mapping: RootedTraceableBox<Heap<*mut JSObject>>,
|
||||||
|
@ -105,7 +105,7 @@ impl GPUBuffer {
|
||||||
self.buffer
|
self.buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn size(&self) -> GPUBufferSize {
|
pub fn size(&self) -> GPUSize64 {
|
||||||
self.size
|
self.size
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,6 +116,10 @@ impl GPUBuffer {
|
||||||
pub fn state(&self) -> Ref<GPUBufferState> {
|
pub fn state(&self) -> Ref<GPUBufferState> {
|
||||||
self.state.borrow()
|
self.state.borrow()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn valid(&self) -> bool {
|
||||||
|
self.valid.get()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for GPUBuffer {
|
impl Drop for GPUBuffer {
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use crate::dom::bindings::cell::DomRefCell;
|
use crate::dom::bindings::cell::DomRefCell;
|
||||||
|
use crate::dom::bindings::codegen::Bindings::GPUBufferBinding::GPUSize64;
|
||||||
use crate::dom::bindings::codegen::Bindings::GPUCommandEncoderBinding::{
|
use crate::dom::bindings::codegen::Bindings::GPUCommandEncoderBinding::{
|
||||||
GPUCommandBufferDescriptor, GPUCommandEncoderMethods, GPUComputePassDescriptor,
|
GPUCommandBufferDescriptor, GPUCommandEncoderMethods, GPUComputePassDescriptor,
|
||||||
};
|
};
|
||||||
|
@ -16,9 +17,23 @@ use crate::dom::gpucommandbuffer::GPUCommandBuffer;
|
||||||
use crate::dom::gpucomputepassencoder::GPUComputePassEncoder;
|
use crate::dom::gpucomputepassencoder::GPUComputePassEncoder;
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
use ipc_channel::ipc;
|
use ipc_channel::ipc;
|
||||||
|
use std::cell::Cell;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
use webgpu::wgpu::resource::BufferUsage;
|
||||||
use webgpu::{WebGPU, WebGPUCommandEncoder, WebGPURequest};
|
use webgpu::{WebGPU, WebGPUCommandEncoder, WebGPURequest};
|
||||||
|
|
||||||
|
const BUFFER_COPY_ALIGN_MASK: u64 = 3;
|
||||||
|
|
||||||
|
// https://gpuweb.github.io/gpuweb/#enumdef-encoder-state
|
||||||
|
#[derive(MallocSizeOf, PartialEq)]
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub enum GPUCommandEncoderState {
|
||||||
|
Open,
|
||||||
|
EncodingRenderPass,
|
||||||
|
EncodingComputePass,
|
||||||
|
Closed,
|
||||||
|
}
|
||||||
|
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
pub struct GPUCommandEncoder {
|
pub struct GPUCommandEncoder {
|
||||||
reflector_: Reflector,
|
reflector_: Reflector,
|
||||||
|
@ -27,16 +42,24 @@ pub struct GPUCommandEncoder {
|
||||||
label: DomRefCell<Option<DOMString>>,
|
label: DomRefCell<Option<DOMString>>,
|
||||||
encoder: WebGPUCommandEncoder,
|
encoder: WebGPUCommandEncoder,
|
||||||
buffers: DomRefCell<HashSet<DomRoot<GPUBuffer>>>,
|
buffers: DomRefCell<HashSet<DomRoot<GPUBuffer>>>,
|
||||||
|
state: DomRefCell<GPUCommandEncoderState>,
|
||||||
|
valid: Cell<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GPUCommandEncoder {
|
impl GPUCommandEncoder {
|
||||||
pub fn new_inherited(channel: WebGPU, encoder: WebGPUCommandEncoder) -> GPUCommandEncoder {
|
pub fn new_inherited(
|
||||||
|
channel: WebGPU,
|
||||||
|
encoder: WebGPUCommandEncoder,
|
||||||
|
valid: bool,
|
||||||
|
) -> GPUCommandEncoder {
|
||||||
GPUCommandEncoder {
|
GPUCommandEncoder {
|
||||||
channel,
|
channel,
|
||||||
reflector_: Reflector::new(),
|
reflector_: Reflector::new(),
|
||||||
label: DomRefCell::new(None),
|
label: DomRefCell::new(None),
|
||||||
encoder,
|
encoder,
|
||||||
buffers: DomRefCell::new(HashSet::new()),
|
buffers: DomRefCell::new(HashSet::new()),
|
||||||
|
state: DomRefCell::new(GPUCommandEncoderState::Open),
|
||||||
|
valid: Cell::new(valid),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,14 +67,30 @@ impl GPUCommandEncoder {
|
||||||
global: &GlobalScope,
|
global: &GlobalScope,
|
||||||
channel: WebGPU,
|
channel: WebGPU,
|
||||||
encoder: WebGPUCommandEncoder,
|
encoder: WebGPUCommandEncoder,
|
||||||
|
valid: bool,
|
||||||
) -> DomRoot<GPUCommandEncoder> {
|
) -> DomRoot<GPUCommandEncoder> {
|
||||||
reflect_dom_object(
|
reflect_dom_object(
|
||||||
Box::new(GPUCommandEncoder::new_inherited(channel, encoder)),
|
Box::new(GPUCommandEncoder::new_inherited(channel, encoder, valid)),
|
||||||
global,
|
global,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl GPUCommandEncoder {
|
||||||
|
pub fn id(&self) -> WebGPUCommandEncoder {
|
||||||
|
self.encoder
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_state(&self, set: GPUCommandEncoderState, expect: GPUCommandEncoderState) {
|
||||||
|
if *self.state.borrow() == expect {
|
||||||
|
*self.state.borrow_mut() = set;
|
||||||
|
} else {
|
||||||
|
self.valid.set(false);
|
||||||
|
*self.state.borrow_mut() = GPUCommandEncoderState::Closed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl GPUCommandEncoderMethods for GPUCommandEncoder {
|
impl GPUCommandEncoderMethods for GPUCommandEncoder {
|
||||||
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
|
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
|
||||||
fn GetLabel(&self) -> Option<DOMString> {
|
fn GetLabel(&self) -> Option<DOMString> {
|
||||||
|
@ -68,18 +107,59 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder {
|
||||||
&self,
|
&self,
|
||||||
_descriptor: &GPUComputePassDescriptor,
|
_descriptor: &GPUComputePassDescriptor,
|
||||||
) -> DomRoot<GPUComputePassEncoder> {
|
) -> DomRoot<GPUComputePassEncoder> {
|
||||||
GPUComputePassEncoder::new(&self.global(), self.channel.clone(), self.encoder)
|
self.set_state(
|
||||||
|
GPUCommandEncoderState::EncodingComputePass,
|
||||||
|
GPUCommandEncoderState::Open,
|
||||||
|
);
|
||||||
|
GPUComputePassEncoder::new(&self.global(), self.channel.clone(), &self)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// https://gpuweb.github.io/gpuweb/#dom-gpucommandencoder-copybuffertobuffer
|
/// https://gpuweb.github.io/gpuweb/#dom-gpucommandencoder-copybuffertobuffer
|
||||||
fn CopyBufferToBuffer(
|
fn CopyBufferToBuffer(
|
||||||
&self,
|
&self,
|
||||||
source: &GPUBuffer,
|
source: &GPUBuffer,
|
||||||
source_offset: u64,
|
source_offset: GPUSize64,
|
||||||
destination: &GPUBuffer,
|
destination: &GPUBuffer,
|
||||||
destination_offset: u64,
|
destination_offset: GPUSize64,
|
||||||
size: u64,
|
size: GPUSize64,
|
||||||
) {
|
) {
|
||||||
|
let mut valid = match source_offset.checked_add(size) {
|
||||||
|
Some(_) => true,
|
||||||
|
None => false,
|
||||||
|
};
|
||||||
|
valid &= match destination_offset.checked_add(size) {
|
||||||
|
Some(_) => true,
|
||||||
|
None => false,
|
||||||
|
};
|
||||||
|
valid &= match BufferUsage::from_bits(source.usage()) {
|
||||||
|
Some(usage) => usage.contains(BufferUsage::COPY_SRC),
|
||||||
|
None => false,
|
||||||
|
};
|
||||||
|
valid &= match BufferUsage::from_bits(destination.usage()) {
|
||||||
|
Some(usage) => usage.contains(BufferUsage::COPY_DST),
|
||||||
|
None => false,
|
||||||
|
};
|
||||||
|
valid &= (*self.state.borrow() == GPUCommandEncoderState::Open) &&
|
||||||
|
source.valid() &&
|
||||||
|
destination.valid() &
|
||||||
|
!(size & BUFFER_COPY_ALIGN_MASK == 0) &
|
||||||
|
!(source_offset & BUFFER_COPY_ALIGN_MASK == 0) &
|
||||||
|
!(destination_offset & BUFFER_COPY_ALIGN_MASK == 0) &
|
||||||
|
(source.size() >= source_offset + size) &
|
||||||
|
(destination.size() >= destination_offset + size);
|
||||||
|
|
||||||
|
if source.id().0 == destination.id().0 {
|
||||||
|
//TODO: maybe forbid this case based on https://github.com/gpuweb/gpuweb/issues/783
|
||||||
|
valid &= source_offset > destination_offset + size ||
|
||||||
|
source_offset + size < destination_offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
if !valid {
|
||||||
|
// TODO: Record an error in the current scope.
|
||||||
|
self.valid.set(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
self.buffers.borrow_mut().insert(DomRoot::from_ref(source));
|
self.buffers.borrow_mut().insert(DomRoot::from_ref(source));
|
||||||
self.buffers
|
self.buffers
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
|
@ -110,6 +190,7 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder {
|
||||||
})
|
})
|
||||||
.expect("Failed to send Finish");
|
.expect("Failed to send Finish");
|
||||||
|
|
||||||
|
*self.state.borrow_mut() = GPUCommandEncoderState::Closed;
|
||||||
let buffer = receiver.recv().unwrap();
|
let buffer = receiver.recv().unwrap();
|
||||||
GPUCommandBuffer::new(
|
GPUCommandBuffer::new(
|
||||||
&self.global(),
|
&self.global(),
|
||||||
|
|
|
@ -5,10 +5,11 @@
|
||||||
use crate::dom::bindings::cell::DomRefCell;
|
use crate::dom::bindings::cell::DomRefCell;
|
||||||
use crate::dom::bindings::codegen::Bindings::GPUComputePassEncoderBinding::GPUComputePassEncoderMethods;
|
use crate::dom::bindings::codegen::Bindings::GPUComputePassEncoderBinding::GPUComputePassEncoderMethods;
|
||||||
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
|
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::DOMString;
|
use crate::dom::bindings::str::DOMString;
|
||||||
use crate::dom::globalscope::GlobalScope;
|
use crate::dom::globalscope::GlobalScope;
|
||||||
use crate::dom::gpubindgroup::GPUBindGroup;
|
use crate::dom::gpubindgroup::GPUBindGroup;
|
||||||
|
use crate::dom::gpucommandencoder::{GPUCommandEncoder, GPUCommandEncoderState};
|
||||||
use crate::dom::gpucomputepipeline::GPUComputePipeline;
|
use crate::dom::gpucomputepipeline::GPUComputePipeline;
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
@ -20,7 +21,7 @@ use webgpu::{
|
||||||
},
|
},
|
||||||
RawPass,
|
RawPass,
|
||||||
},
|
},
|
||||||
WebGPU, WebGPUCommandEncoder, WebGPURequest,
|
WebGPU, WebGPURequest,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
|
@ -31,22 +32,24 @@ pub struct GPUComputePassEncoder {
|
||||||
label: DomRefCell<Option<DOMString>>,
|
label: DomRefCell<Option<DOMString>>,
|
||||||
#[ignore_malloc_size_of = "defined in wgpu-core"]
|
#[ignore_malloc_size_of = "defined in wgpu-core"]
|
||||||
raw_pass: RefCell<Option<RawPass>>,
|
raw_pass: RefCell<Option<RawPass>>,
|
||||||
|
command_encoder: Dom<GPUCommandEncoder>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl GPUComputePassEncoder {
|
impl GPUComputePassEncoder {
|
||||||
fn new_inherited(channel: WebGPU, parent: WebGPUCommandEncoder) -> GPUComputePassEncoder {
|
fn new_inherited(channel: WebGPU, parent: &GPUCommandEncoder) -> GPUComputePassEncoder {
|
||||||
GPUComputePassEncoder {
|
GPUComputePassEncoder {
|
||||||
channel,
|
channel,
|
||||||
reflector_: Reflector::new(),
|
reflector_: Reflector::new(),
|
||||||
label: DomRefCell::new(None),
|
label: DomRefCell::new(None),
|
||||||
raw_pass: RefCell::new(Some(RawPass::new_compute(parent.0))),
|
raw_pass: RefCell::new(Some(RawPass::new_compute(parent.id().0))),
|
||||||
|
command_encoder: Dom::from_ref(parent),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(
|
pub fn new(
|
||||||
global: &GlobalScope,
|
global: &GlobalScope,
|
||||||
channel: WebGPU,
|
channel: WebGPU,
|
||||||
parent: WebGPUCommandEncoder,
|
parent: &GPUCommandEncoder,
|
||||||
) -> DomRoot<GPUComputePassEncoder> {
|
) -> DomRoot<GPUComputePassEncoder> {
|
||||||
reflect_dom_object(
|
reflect_dom_object(
|
||||||
Box::new(GPUComputePassEncoder::new_inherited(channel, parent)),
|
Box::new(GPUComputePassEncoder::new_inherited(channel, parent)),
|
||||||
|
@ -87,6 +90,11 @@ impl GPUComputePassEncoderMethods for GPUComputePassEncoder {
|
||||||
pass_data,
|
pass_data,
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
self.command_encoder.set_state(
|
||||||
|
GPUCommandEncoderState::Open,
|
||||||
|
GPUCommandEncoderState::EncodingComputePass,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ use crate::dom::bindings::cell::DomRefCell;
|
||||||
use crate::dom::bindings::codegen::Bindings::GPUAdapterBinding::GPULimits;
|
use crate::dom::bindings::codegen::Bindings::GPUAdapterBinding::GPULimits;
|
||||||
use crate::dom::bindings::codegen::Bindings::GPUBindGroupBinding::GPUBindGroupDescriptor;
|
use crate::dom::bindings::codegen::Bindings::GPUBindGroupBinding::GPUBindGroupDescriptor;
|
||||||
use crate::dom::bindings::codegen::Bindings::GPUBindGroupLayoutBinding::{
|
use crate::dom::bindings::codegen::Bindings::GPUBindGroupLayoutBinding::{
|
||||||
GPUBindGroupLayoutBindings, GPUBindGroupLayoutDescriptor, GPUBindingType,
|
GPUBindGroupLayoutDescriptor, GPUBindGroupLayoutEntry, GPUBindingType,
|
||||||
};
|
};
|
||||||
use crate::dom::bindings::codegen::Bindings::GPUBufferBinding::GPUBufferDescriptor;
|
use crate::dom::bindings::codegen::Bindings::GPUBufferBinding::GPUBufferDescriptor;
|
||||||
use crate::dom::bindings::codegen::Bindings::GPUComputePipelineBinding::GPUComputePipelineDescriptor;
|
use crate::dom::bindings::codegen::Bindings::GPUComputePipelineBinding::GPUComputePipelineDescriptor;
|
||||||
|
@ -295,7 +295,7 @@ impl GPUDeviceMethods for GPUDevice {
|
||||||
let mut valid = true;
|
let mut valid = true;
|
||||||
|
|
||||||
let bindings = descriptor
|
let bindings = descriptor
|
||||||
.bindings
|
.entries
|
||||||
.iter()
|
.iter()
|
||||||
.map(|bind| {
|
.map(|bind| {
|
||||||
// TODO: binding must be >= 0
|
// TODO: binding must be >= 0
|
||||||
|
@ -410,9 +410,9 @@ impl GPUDeviceMethods for GPUDevice {
|
||||||
let bgl = receiver.recv().unwrap();
|
let bgl = receiver.recv().unwrap();
|
||||||
|
|
||||||
let binds = descriptor
|
let binds = descriptor
|
||||||
.bindings
|
.entries
|
||||||
.iter()
|
.iter()
|
||||||
.map(|bind| GPUBindGroupLayoutBindings {
|
.map(|bind| GPUBindGroupLayoutEntry {
|
||||||
binding: bind.binding,
|
binding: bind.binding,
|
||||||
hasDynamicOffset: bind.hasDynamicOffset,
|
hasDynamicOffset: bind.hasDynamicOffset,
|
||||||
multisampled: bind.multisampled,
|
multisampled: bind.multisampled,
|
||||||
|
@ -494,9 +494,9 @@ impl GPUDeviceMethods for GPUDevice {
|
||||||
/// https://gpuweb.github.io/gpuweb/#dom-gpudevice-createbindgroup
|
/// https://gpuweb.github.io/gpuweb/#dom-gpudevice-createbindgroup
|
||||||
fn CreateBindGroup(&self, descriptor: &GPUBindGroupDescriptor) -> DomRoot<GPUBindGroup> {
|
fn CreateBindGroup(&self, descriptor: &GPUBindGroupDescriptor) -> DomRoot<GPUBindGroup> {
|
||||||
let alignment: u64 = 256;
|
let alignment: u64 = 256;
|
||||||
let mut valid = descriptor.layout.bindings().len() == descriptor.bindings.len();
|
let mut valid = descriptor.layout.bindings().len() == descriptor.entries.len();
|
||||||
|
|
||||||
valid &= descriptor.bindings.iter().all(|bind| {
|
valid &= descriptor.entries.iter().all(|bind| {
|
||||||
let buffer_size = bind.resource.buffer.size();
|
let buffer_size = bind.resource.buffer.size();
|
||||||
let resource_size = bind.resource.size.unwrap_or(buffer_size);
|
let resource_size = bind.resource.size.unwrap_or(buffer_size);
|
||||||
let length = bind.resource.offset.checked_add(resource_size);
|
let length = bind.resource.offset.checked_add(resource_size);
|
||||||
|
@ -521,7 +521,7 @@ impl GPUDeviceMethods for GPUDevice {
|
||||||
});
|
});
|
||||||
|
|
||||||
let bindings = descriptor
|
let bindings = descriptor
|
||||||
.bindings
|
.entries
|
||||||
.iter()
|
.iter()
|
||||||
.map(|bind| BindGroupBinding {
|
.map(|bind| BindGroupBinding {
|
||||||
binding: bind.binding,
|
binding: bind.binding,
|
||||||
|
@ -632,6 +632,6 @@ impl GPUDeviceMethods for GPUDevice {
|
||||||
.expect("Failed to create WebGPU command encoder");
|
.expect("Failed to create WebGPU command encoder");
|
||||||
let encoder = receiver.recv().unwrap();
|
let encoder = receiver.recv().unwrap();
|
||||||
|
|
||||||
GPUCommandEncoder::new(&self.global(), self.channel.clone(), encoder)
|
GPUCommandEncoder::new(&self.global(), self.channel.clone(), encoder, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,14 +10,12 @@ GPUBindGroup includes GPUObjectBase;
|
||||||
|
|
||||||
dictionary GPUBindGroupDescriptor : GPUObjectDescriptorBase {
|
dictionary GPUBindGroupDescriptor : GPUObjectDescriptorBase {
|
||||||
required GPUBindGroupLayout layout;
|
required GPUBindGroupLayout layout;
|
||||||
required sequence<GPUBindGroupBindings> bindings;
|
required sequence<GPUBindGroupEntry> entries;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef /*(GPUSampler or GPUTextureView or*/ GPUBufferBindings/*)*/ GPUBindingResource;
|
typedef /*(GPUSampler or GPUTextureView or*/ GPUBufferBindings/*)*/ GPUBindingResource;
|
||||||
|
|
||||||
// Note: Servo codegen doesn't like the name `GPUBindGroupBinding` because it's already occupied
|
dictionary GPUBindGroupEntry {
|
||||||
// dictionary GPUBindGroupBinding {
|
|
||||||
dictionary GPUBindGroupBindings {
|
|
||||||
required unsigned long binding;
|
required unsigned long binding;
|
||||||
required GPUBindingResource resource;
|
required GPUBindingResource resource;
|
||||||
};
|
};
|
||||||
|
@ -26,6 +24,6 @@ dictionary GPUBindGroupBindings {
|
||||||
// dictionary GPUBufferBinding {
|
// dictionary GPUBufferBinding {
|
||||||
dictionary GPUBufferBindings {
|
dictionary GPUBufferBindings {
|
||||||
required GPUBuffer buffer;
|
required GPUBuffer buffer;
|
||||||
GPUBufferSize offset = 0;
|
GPUSize64 offset = 0;
|
||||||
GPUBufferSize size;
|
GPUSize64 size;
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,12 +9,10 @@ interface GPUBindGroupLayout {
|
||||||
GPUBindGroupLayout includes GPUObjectBase;
|
GPUBindGroupLayout includes GPUObjectBase;
|
||||||
|
|
||||||
dictionary GPUBindGroupLayoutDescriptor : GPUObjectDescriptorBase {
|
dictionary GPUBindGroupLayoutDescriptor : GPUObjectDescriptorBase {
|
||||||
required sequence<GPUBindGroupLayoutBindings> bindings;
|
required sequence<GPUBindGroupLayoutEntry> entries;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Note: Servo codegen doesn't like the name `GPUBindGroupLayoutBinding` because it's already occupied
|
dictionary GPUBindGroupLayoutEntry {
|
||||||
// dictionary GPUBindGroupLayoutBinding {
|
|
||||||
dictionary GPUBindGroupLayoutBindings {
|
|
||||||
required unsigned long binding;
|
required unsigned long binding;
|
||||||
required GPUShaderStageFlags visibility;
|
required GPUShaderStageFlags visibility;
|
||||||
required GPUBindingType type;
|
required GPUBindingType type;
|
||||||
|
|
|
@ -14,11 +14,11 @@ interface GPUBuffer {
|
||||||
GPUBuffer includes GPUObjectBase;
|
GPUBuffer includes GPUObjectBase;
|
||||||
|
|
||||||
dictionary GPUBufferDescriptor : GPUObjectDescriptorBase {
|
dictionary GPUBufferDescriptor : GPUObjectDescriptorBase {
|
||||||
required GPUBufferSize size;
|
required GPUSize64 size;
|
||||||
required GPUBufferUsageFlags usage;
|
required GPUBufferUsageFlags usage;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef unsigned long long GPUBufferSize;
|
typedef unsigned long long GPUSize64;
|
||||||
|
|
||||||
typedef unsigned long GPUBufferUsageFlags;
|
typedef unsigned long GPUBufferUsageFlags;
|
||||||
|
|
||||||
|
|
|
@ -10,10 +10,10 @@ interface GPUCommandEncoder {
|
||||||
|
|
||||||
void copyBufferToBuffer(
|
void copyBufferToBuffer(
|
||||||
GPUBuffer source,
|
GPUBuffer source,
|
||||||
GPUBufferSize sourceOffset,
|
GPUSize64 sourceOffset,
|
||||||
GPUBuffer destination,
|
GPUBuffer destination,
|
||||||
GPUBufferSize destinationOffset,
|
GPUSize64 destinationOffset,
|
||||||
GPUBufferSize size);
|
GPUSize64 size);
|
||||||
|
|
||||||
// void copyBufferToTexture(
|
// void copyBufferToTexture(
|
||||||
// GPUBufferCopyView source,
|
// GPUBufferCopyView source,
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
interface GPUComputePassEncoder {
|
interface GPUComputePassEncoder {
|
||||||
void setPipeline(GPUComputePipeline pipeline);
|
void setPipeline(GPUComputePipeline pipeline);
|
||||||
void dispatch(GPUSize32 x, optional GPUSize32 y = 1, optional GPUSize32 z = 1);
|
void dispatch(GPUSize32 x, optional GPUSize32 y = 1, optional GPUSize32 z = 1);
|
||||||
// void dispatchIndirect(GPUBuffer indirectBuffer, GPUBufferSize indirectOffset);
|
// void dispatchIndirect(GPUBuffer indirectBuffer, GPUSize64 indirectOffset);
|
||||||
|
|
||||||
void endPass();
|
void endPass();
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue