Implement GPUPipelineBase for implicit pipeline layouts

This commit is contained in:
Kunal Mohan 2020-08-19 16:44:26 +05:30
parent 8c576bb02b
commit f082a507da
7 changed files with 176 additions and 25 deletions

View file

@ -3,28 +3,37 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::GPUAdapterBinding::GPULimits;
use crate::dom::bindings::codegen::Bindings::GPUComputePipelineBinding::GPUComputePipelineMethods;
use crate::dom::bindings::reflector::reflect_dom_object;
use crate::dom::bindings::reflector::Reflector;
use crate::dom::bindings::error::{Error, Fallible};
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::USVString;
use crate::dom::globalscope::GlobalScope;
use crate::dom::gpubindgrouplayout::GPUBindGroupLayout;
use dom_struct::dom_struct;
use webgpu::WebGPUComputePipeline;
use std::string::String;
use webgpu::{WebGPUBindGroupLayout, WebGPUComputePipeline};
#[dom_struct]
pub struct GPUComputePipeline {
reflector_: Reflector,
label: DomRefCell<Option<USVString>>,
compute_pipeline: WebGPUComputePipeline,
bind_group_layouts: Vec<WebGPUBindGroupLayout>,
}
impl GPUComputePipeline {
fn new_inherited(compute_pipeline: WebGPUComputePipeline, label: Option<USVString>) -> Self {
fn new_inherited(
compute_pipeline: WebGPUComputePipeline,
label: Option<USVString>,
bgls: Vec<WebGPUBindGroupLayout>,
) -> Self {
Self {
reflector_: Reflector::new(),
label: DomRefCell::new(label),
compute_pipeline,
bind_group_layouts: bgls,
}
}
@ -32,9 +41,14 @@ impl GPUComputePipeline {
global: &GlobalScope,
compute_pipeline: WebGPUComputePipeline,
label: Option<USVString>,
bgls: Vec<WebGPUBindGroupLayout>,
) -> DomRoot<Self> {
reflect_dom_object(
Box::new(GPUComputePipeline::new_inherited(compute_pipeline, label)),
Box::new(GPUComputePipeline::new_inherited(
compute_pipeline,
label,
bgls,
)),
global,
)
}
@ -56,4 +70,17 @@ impl GPUComputePipelineMethods for GPUComputePipeline {
fn SetLabel(&self, value: Option<USVString>) {
*self.label.borrow_mut() = value;
}
/// https://gpuweb.github.io/gpuweb/#dom-gpupipelinebase-getbindgrouplayout
fn GetBindGroupLayout(&self, index: u32) -> Fallible<DomRoot<GPUBindGroupLayout>> {
if index > self.bind_group_layouts.len() as u32 || index > GPULimits::empty().maxBindGroups
{
return Err(Error::Range(String::from("Index out of bounds")));
}
return Ok(GPUBindGroupLayout::new(
&self.global(),
self.bind_group_layouts[index as usize],
None,
));
}
}