Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement GPURenderPipeline #26714

Merged
merged 2 commits into from May 30, 2020
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Prev

Implement GPURenderPipeline

Add webidl for GPURenderPipeline and implement GPUDevice.createRenderPipeline()
  • Loading branch information
kunalmohan committed May 30, 2020
commit 130de8b8e645867c5c834655d8b94defea599681

Some generated files are not rendered by default. Learn more.

@@ -32,6 +32,7 @@ serde_json = "1.0"
[dependencies]
accountable-refcell = { version = "0.2.0", optional = true }
app_units = "0.7"
arrayvec = "0.5.1"
backtrace = { version = "0.3", optional = true }
base64 = "0.10.1"
bitflags = "1.0"
@@ -160,7 +160,7 @@ use uuid::Uuid;
use webgpu::{
wgpu::command::RawPass, WebGPU, WebGPUAdapter, WebGPUBindGroup, WebGPUBindGroupLayout,
WebGPUBuffer, WebGPUCommandBuffer, WebGPUCommandEncoder, WebGPUComputePipeline, WebGPUDevice,
WebGPUPipelineLayout, WebGPUQueue, WebGPUSampler, WebGPUShaderModule,
WebGPUPipelineLayout, WebGPUQueue, WebGPURenderPipeline, WebGPUSampler, WebGPUShaderModule,
};
use webrender_api::{DocumentId, ImageKey};
use webxr_api::SwapChainId as WebXRSwapChainId;
@@ -556,6 +556,7 @@ unsafe_no_jsmanaged_fields!(WebGPUBuffer);
unsafe_no_jsmanaged_fields!(WebGPUBindGroup);
unsafe_no_jsmanaged_fields!(WebGPUBindGroupLayout);
unsafe_no_jsmanaged_fields!(WebGPUComputePipeline);
unsafe_no_jsmanaged_fields!(WebGPURenderPipeline);
unsafe_no_jsmanaged_fields!(WebGPUPipelineLayout);
unsafe_no_jsmanaged_fields!(WebGPUQueue);
unsafe_no_jsmanaged_fields!(WebGPUShaderModule);
@@ -0,0 +1,11 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use crate::dom::bindings::reflector::Reflector;
use dom_struct::dom_struct;

#[dom_struct]
pub struct GPUColorWrite {
reflector_: Reflector,
}

Large diffs are not rendered by default.

@@ -57,6 +57,10 @@ impl GPUPipelineLayout {
pub fn id(&self) -> WebGPUPipelineLayout {
self.pipeline_layout
}

pub fn is_valid(&self) -> bool {
self.valid.get()
}
}

impl GPUPipelineLayoutMethods for GPUPipelineLayout {
@@ -0,0 +1,67 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::GPURenderPipelineBinding::GPURenderPipelineMethods;
use crate::dom::bindings::reflector::reflect_dom_object;
use crate::dom::bindings::reflector::Reflector;
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
use crate::dom::globalscope::GlobalScope;
use dom_struct::dom_struct;
use std::cell::Cell;
use webgpu::{WebGPUDevice, WebGPURenderPipeline};

#[dom_struct]
pub struct GPURenderPipeline {
reflector_: Reflector,
label: DomRefCell<Option<DOMString>>,
render_pipeline: WebGPURenderPipeline,
device: WebGPUDevice,
valid: Cell<bool>,
}

impl GPURenderPipeline {
fn new_inherited(
render_pipeline: WebGPURenderPipeline,
device: WebGPUDevice,
valid: bool,
) -> GPURenderPipeline {
Self {
reflector_: Reflector::new(),
label: DomRefCell::new(None),
render_pipeline,
valid: Cell::new(valid),
device,
}
}

pub fn new(
global: &GlobalScope,
render_pipeline: WebGPURenderPipeline,
device: WebGPUDevice,
valid: bool,
) -> DomRoot<GPURenderPipeline> {
reflect_dom_object(
Box::new(GPURenderPipeline::new_inherited(
render_pipeline,
device,
valid,
)),
global,
)
}
}

impl GPURenderPipelineMethods for GPURenderPipeline {
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn GetLabel(&self) -> Option<DOMString> {
self.label.borrow().clone()
}

/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
fn SetLabel(&self, value: Option<DOMString>) {
*self.label.borrow_mut() = value;
}
}
@@ -7,7 +7,7 @@ use webgpu::wgpu::{
hub::IdentityManager,
id::{
AdapterId, BindGroupId, BindGroupLayoutId, BufferId, CommandEncoderId, ComputePipelineId,
DeviceId, PipelineLayoutId, SamplerId, ShaderModuleId,
DeviceId, PipelineLayoutId, RenderPipelineId, SamplerId, ShaderModuleId,
},
};
use webgpu::wgt::Backend;
@@ -24,6 +24,7 @@ pub struct IdentityHub {
shader_modules: IdentityManager,
command_encoders: IdentityManager,
samplers: IdentityManager,
render_pipelines: IdentityManager,
}

impl IdentityHub {
@@ -39,6 +40,7 @@ impl IdentityHub {
shader_modules: IdentityManager::default(),
command_encoders: IdentityManager::default(),
samplers: IdentityManager::default(),
render_pipelines: IdentityManager::default(),
}
}
}
@@ -184,4 +186,12 @@ impl Identities {
pub fn kill_sampler_id(&mut self, id: SamplerId) {
self.select(id.backend()).samplers.free(id);
}

pub fn create_render_pipeline_id(&mut self, backend: Backend) -> RenderPipelineId {
self.select(backend).render_pipelines.alloc(backend)
}

pub fn kill_render_pipeline_id(&mut self, id: RenderPipelineId) {
self.select(id.backend()).render_pipelines.free(id);
}
}
@@ -325,13 +325,15 @@ pub mod gpubindgroup;
pub mod gpubindgrouplayout;
pub mod gpubuffer;
pub mod gpubufferusage;
pub mod gpucolorwrite;
pub mod gpucommandbuffer;
pub mod gpucommandencoder;
pub mod gpucomputepassencoder;
pub mod gpucomputepipeline;
pub mod gpudevice;
pub mod gpupipelinelayout;
pub mod gpuqueue;
pub mod gpurenderpipeline;
pub mod gpusampler;
pub mod gpushadermodule;
pub mod gpushaderstage;
@@ -0,0 +1,15 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

// https://gpuweb.github.io/gpuweb/#gpucolorwrite
[Exposed=(Window, DedicatedWorker), Pref="dom.webgpu.enabled"]
interface GPUColorWrite {
const GPUColorWriteFlags RED = 0x1;
const GPUColorWriteFlags GREEN = 0x2;
const GPUColorWriteFlags BLUE = 0x4;
const GPUColorWriteFlags ALPHA = 0x8;
const GPUColorWriteFlags ALL = 0xF;
};

typedef [EnforceRange] unsigned long GPUColorWriteFlags;
@@ -22,7 +22,7 @@ interface GPUDevice : EventTarget {

GPUShaderModule createShaderModule(GPUShaderModuleDescriptor descriptor);
GPUComputePipeline createComputePipeline(GPUComputePipelineDescriptor descriptor);
// GPURenderPipeline createRenderPipeline(GPURenderPipelineDescriptor descriptor);
GPURenderPipeline createRenderPipeline(GPURenderPipelineDescriptor descriptor);

GPUCommandEncoder createCommandEncoder(optional GPUCommandEncoderDescriptor descriptor = {});
// GPURenderBundleEncoder createRenderBundleEncoder(GPURenderBundleEncoderDescriptor descriptor);
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.