summaryrefslogtreecommitdiff
path: root/ext/webgpu/pipeline.rs
diff options
context:
space:
mode:
authorLeo Kettmeir <crowlkats@toaxl.com>2024-05-05 07:22:18 -0700
committerGitHub <noreply@github.com>2024-05-05 07:22:18 -0700
commitcd12d416271e9e9fd0f00303525021f75688ff9f (patch)
treeaf1fd7a88590e37b09e61ae5a1aaeec4c325b907 /ext/webgpu/pipeline.rs
parentb2628e4a069ed9fc13f34f6e4fd75f29c657e5a9 (diff)
chore: update wgpu (#23684)
Diffstat (limited to 'ext/webgpu/pipeline.rs')
-rw-r--r--ext/webgpu/pipeline.rs54
1 files changed, 30 insertions, 24 deletions
diff --git a/ext/webgpu/pipeline.rs b/ext/webgpu/pipeline.rs
index 4e8f5f6f9..a6b0cb8ce 100644
--- a/ext/webgpu/pipeline.rs
+++ b/ext/webgpu/pipeline.rs
@@ -8,6 +8,7 @@ use deno_core::ResourceId;
use serde::Deserialize;
use serde::Serialize;
use std::borrow::Cow;
+use std::collections::HashMap;
use std::rc::Rc;
use super::error::WebGpuError;
@@ -25,8 +26,7 @@ impl Resource for WebGpuPipelineLayout {
}
fn close(self: Rc<Self>) {
- let instance = &self.0;
- gfx_select!(self.1 => instance.pipeline_layout_drop(self.1));
+ gfx_select!(self.1 => self.0.pipeline_layout_drop(self.1));
}
}
@@ -40,8 +40,7 @@ impl Resource for WebGpuComputePipeline {
}
fn close(self: Rc<Self>) {
- let instance = &self.0;
- gfx_select!(self.1 => instance.compute_pipeline_drop(self.1));
+ gfx_select!(self.1 => self.0.compute_pipeline_drop(self.1));
}
}
@@ -55,8 +54,7 @@ impl Resource for WebGpuRenderPipeline {
}
fn close(self: Rc<Self>) {
- let instance = &self.0;
- gfx_select!(self.1 => instance.render_pipeline_drop(self.1));
+ gfx_select!(self.1 => self.0.render_pipeline_drop(self.1));
}
}
@@ -77,8 +75,8 @@ pub enum GPUPipelineLayoutOrGPUAutoLayoutMode {
#[serde(rename_all = "camelCase")]
pub struct GpuProgrammableStage {
module: ResourceId,
- entry_point: String,
- // constants: HashMap<String, GPUPipelineConstantValue>
+ entry_point: Option<String>,
+ constants: Option<HashMap<String, f64>>,
}
#[op2]
@@ -114,16 +112,17 @@ pub fn op_webgpu_create_compute_pipeline(
layout: pipeline_layout,
stage: wgpu_core::pipeline::ProgrammableStageDescriptor {
module: compute_shader_module_resource.1,
- entry_point: Cow::from(compute.entry_point),
- // TODO(lucacasonato): support args.compute.constants
+ entry_point: compute.entry_point.map(Cow::from),
+ constants: Cow::Owned(compute.constants.unwrap_or_default()),
+ zero_initialize_workgroup_memory: true,
},
};
let implicit_pipelines = match layout {
GPUPipelineLayoutOrGPUAutoLayoutMode::Layout(_) => None,
GPUPipelineLayoutOrGPUAutoLayoutMode::Auto(GPUAutoLayoutMode::Auto) => {
Some(wgpu_core::device::ImplicitPipelineIds {
- root_id: (),
- group_ids: &[(); MAX_BIND_GROUPS],
+ root_id: None,
+ group_ids: &[None; MAX_BIND_GROUPS],
})
}
};
@@ -131,7 +130,7 @@ pub fn op_webgpu_create_compute_pipeline(
let (compute_pipeline, maybe_err) = gfx_select!(device => instance.device_create_compute_pipeline(
device,
&descriptor,
- (),
+ None,
implicit_pipelines
));
@@ -163,7 +162,7 @@ pub fn op_webgpu_compute_pipeline_get_bind_group_layout(
.get::<WebGpuComputePipeline>(compute_pipeline_rid)?;
let compute_pipeline = compute_pipeline_resource.1;
- let (bind_group_layout, maybe_err) = gfx_select!(compute_pipeline => instance.compute_pipeline_get_bind_group_layout(compute_pipeline, index, ()));
+ let (bind_group_layout, maybe_err) = gfx_select!(compute_pipeline => instance.compute_pipeline_get_bind_group_layout(compute_pipeline, index, None));
let label = gfx_select!(bind_group_layout => instance.bind_group_layout_label(bind_group_layout));
@@ -285,7 +284,8 @@ impl<'a> From<GpuVertexBufferLayout>
#[serde(rename_all = "camelCase")]
struct GpuVertexState {
module: ResourceId,
- entry_point: String,
+ entry_point: Option<String>,
+ constants: Option<HashMap<String, f64>>,
buffers: Vec<Option<GpuVertexBufferLayout>>,
}
@@ -312,8 +312,8 @@ impl From<GpuMultisampleState> for wgpu_types::MultisampleState {
struct GpuFragmentState {
targets: Vec<Option<wgpu_types::ColorTargetState>>,
module: u32,
- entry_point: String,
- // TODO(lucacasonato): constants
+ entry_point: Option<String>,
+ constants: Option<HashMap<String, f64>>,
}
#[derive(Deserialize)]
@@ -364,9 +364,12 @@ pub fn op_webgpu_create_render_pipeline(
Some(wgpu_core::pipeline::FragmentState {
stage: wgpu_core::pipeline::ProgrammableStageDescriptor {
module: fragment_shader_module_resource.1,
- entry_point: Cow::from(fragment.entry_point),
+ entry_point: fragment.entry_point.map(Cow::from),
+ constants: Cow::Owned(fragment.constants.unwrap_or_default()),
+ // Required to be true for WebGPU
+ zero_initialize_workgroup_memory: true,
},
- targets: Cow::from(fragment.targets),
+ targets: Cow::Owned(fragment.targets),
})
} else {
None
@@ -386,7 +389,10 @@ pub fn op_webgpu_create_render_pipeline(
vertex: wgpu_core::pipeline::VertexState {
stage: wgpu_core::pipeline::ProgrammableStageDescriptor {
module: vertex_shader_module_resource.1,
- entry_point: Cow::Owned(args.vertex.entry_point),
+ entry_point: args.vertex.entry_point.map(Cow::Owned),
+ constants: Cow::Owned(args.vertex.constants.unwrap_or_default()),
+ // Required to be true for WebGPU
+ zero_initialize_workgroup_memory: true,
},
buffers: Cow::Owned(vertex_buffers),
},
@@ -401,8 +407,8 @@ pub fn op_webgpu_create_render_pipeline(
GPUPipelineLayoutOrGPUAutoLayoutMode::Layout(_) => None,
GPUPipelineLayoutOrGPUAutoLayoutMode::Auto(GPUAutoLayoutMode::Auto) => {
Some(wgpu_core::device::ImplicitPipelineIds {
- root_id: (),
- group_ids: &[(); MAX_BIND_GROUPS],
+ root_id: None,
+ group_ids: &[None; MAX_BIND_GROUPS],
})
}
};
@@ -410,7 +416,7 @@ pub fn op_webgpu_create_render_pipeline(
let (render_pipeline, maybe_err) = gfx_select!(device => instance.device_create_render_pipeline(
device,
&descriptor,
- (),
+ None,
implicit_pipelines
));
@@ -434,7 +440,7 @@ pub fn op_webgpu_render_pipeline_get_bind_group_layout(
.get::<WebGpuRenderPipeline>(render_pipeline_rid)?;
let render_pipeline = render_pipeline_resource.1;
- let (bind_group_layout, maybe_err) = gfx_select!(render_pipeline => instance.render_pipeline_get_bind_group_layout(render_pipeline, index, ()));
+ let (bind_group_layout, maybe_err) = gfx_select!(render_pipeline => instance.render_pipeline_get_bind_group_layout(render_pipeline, index, None));
let label = gfx_select!(bind_group_layout => instance.bind_group_layout_label(bind_group_layout));