Skip to content

Commit

Permalink
feat(shader)!: make ProgrammableStage::entry_point optional
Browse files Browse the repository at this point in the history
  • Loading branch information
ErichDonGubler committed Mar 7, 2024
1 parent e447a89 commit 8bfc721
Show file tree
Hide file tree
Showing 43 changed files with 130 additions and 115 deletions.
12 changes: 6 additions & 6 deletions deno_webgpu/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub enum GPUPipelineLayoutOrGPUAutoLayoutMode {
#[serde(rename_all = "camelCase")]
pub struct GpuProgrammableStage {
module: ResourceId,
entry_point: String,
entry_point: Option<String>,
// constants: HashMap<String, GPUPipelineConstantValue>
}

Expand Down Expand Up @@ -110,7 +110,7 @@ pub fn op_webgpu_create_compute_pipeline(
layout: pipeline_layout,
stage: wgpu_core::pipeline::ProgrammableStageDescriptor {
module: compute_shader_module_resource.1,
entry_point: Some(Cow::from(compute.entry_point)),
entry_point: compute.entry_point.map(Cow::from),
// TODO(lucacasonato): support args.compute.constants
},
};
Expand Down Expand Up @@ -278,7 +278,7 @@ impl<'a> From<GpuVertexBufferLayout> for wgpu_core::pipeline::VertexBufferLayout
#[serde(rename_all = "camelCase")]
struct GpuVertexState {
module: ResourceId,
entry_point: String,
entry_point: Option<String>,
buffers: Vec<Option<GpuVertexBufferLayout>>,
}

Expand All @@ -305,7 +305,7 @@ impl From<GpuMultisampleState> for wgpu_types::MultisampleState {
struct GpuFragmentState {
targets: Vec<Option<wgpu_types::ColorTargetState>>,
module: u32,
entry_point: String,
entry_point: Option<String>,
// TODO(lucacasonato): constants
}

Expand Down Expand Up @@ -355,7 +355,7 @@ 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: Some(Cow::from(fragment.entry_point)),
entry_point: fragment.entry_point.map(Cow::from),
},
targets: Cow::from(fragment.targets),
})
Expand All @@ -377,7 +377,7 @@ 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: Some(Cow::Owned(args.vertex.entry_point)),
entry_point: args.vertex.entry_point.map(Cow::from),
},
buffers: Cow::Owned(vertex_buffers),
},
Expand Down
6 changes: 3 additions & 3 deletions examples/src/boids/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl crate::framework::Example for Example {
layout: Some(&render_pipeline_layout),
vertex: wgpu::VertexState {
module: &draw_shader,
entry_point: "main_vs",
entry_point: Some("main_vs"),
buffers: &[
wgpu::VertexBufferLayout {
array_stride: 4 * 4,
Expand All @@ -147,7 +147,7 @@ impl crate::framework::Example for Example {
},
fragment: Some(wgpu::FragmentState {
module: &draw_shader,
entry_point: "main_fs",
entry_point: Some("main_fs"),
targets: &[Some(config.view_formats[0].into())],
}),
primitive: wgpu::PrimitiveState::default(),
Expand All @@ -162,7 +162,7 @@ impl crate::framework::Example for Example {
label: Some("Compute pipeline"),
layout: Some(&compute_pipeline_layout),
module: &compute_shader,
entry_point: "main",
entry_point: Some("main"),
});

// buffer for the three 2d triangle vertices of each instance
Expand Down
4 changes: 2 additions & 2 deletions examples/src/bunnymark/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,12 @@ impl crate::framework::Example for Example {
layout: Some(&pipeline_layout),
vertex: wgpu::VertexState {
module: &shader,
entry_point: "vs_main",
entry_point: Some("vs_main"),
buffers: &[],
},
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: "fs_main",
entry_point: Some("fs_main"),
targets: &[Some(wgpu::ColorTargetState {
format: config.view_formats[0],
blend: Some(wgpu::BlendState::ALPHA_BLENDING),
Expand Down
16 changes: 8 additions & 8 deletions examples/src/conservative_raster/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ impl crate::framework::Example for Example {
layout: Some(&pipeline_layout_empty),
vertex: wgpu::VertexState {
module: &shader_triangle_and_lines,
entry_point: "vs_main",
entry_point: Some("vs_main"),
buffers: &[],
},
fragment: Some(wgpu::FragmentState {
module: &shader_triangle_and_lines,
entry_point: "fs_main_red",
entry_point: Some("fs_main_red"),
targets: &[Some(RENDER_TARGET_FORMAT.into())],
}),
primitive: wgpu::PrimitiveState {
Expand All @@ -119,12 +119,12 @@ impl crate::framework::Example for Example {
layout: Some(&pipeline_layout_empty),
vertex: wgpu::VertexState {
module: &shader_triangle_and_lines,
entry_point: "vs_main",
entry_point: Some("vs_main"),
buffers: &[],
},
fragment: Some(wgpu::FragmentState {
module: &shader_triangle_and_lines,
entry_point: "fs_main_blue",
entry_point: Some("fs_main_blue"),
targets: &[Some(RENDER_TARGET_FORMAT.into())],
}),
primitive: wgpu::PrimitiveState::default(),
Expand All @@ -143,12 +143,12 @@ impl crate::framework::Example for Example {
layout: Some(&pipeline_layout_empty),
vertex: wgpu::VertexState {
module: &shader_triangle_and_lines,
entry_point: "vs_main",
entry_point: Some("vs_main"),
buffers: &[],
},
fragment: Some(wgpu::FragmentState {
module: &shader_triangle_and_lines,
entry_point: "fs_main_white",
entry_point: Some("fs_main_white"),
targets: &[Some(config.view_formats[0].into())],
}),
primitive: wgpu::PrimitiveState {
Expand Down Expand Up @@ -204,12 +204,12 @@ impl crate::framework::Example for Example {
layout: Some(&pipeline_layout),
vertex: wgpu::VertexState {
module: &shader,
entry_point: "vs_main",
entry_point: Some("vs_main"),
buffers: &[],
},
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: "fs_main",
entry_point: Some("fs_main"),
targets: &[Some(config.view_formats[0].into())],
}),
primitive: wgpu::PrimitiveState::default(),
Expand Down
8 changes: 4 additions & 4 deletions examples/src/cube/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,12 @@ impl crate::framework::Example for Example {
layout: Some(&pipeline_layout),
vertex: wgpu::VertexState {
module: &shader,
entry_point: "vs_main",
entry_point: Some("vs_main"),
buffers: &vertex_buffers,
},
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: "fs_main",
entry_point: Some("fs_main"),
targets: &[Some(config.view_formats[0].into())],
}),
primitive: wgpu::PrimitiveState {
Expand All @@ -269,12 +269,12 @@ impl crate::framework::Example for Example {
layout: Some(&pipeline_layout),
vertex: wgpu::VertexState {
module: &shader,
entry_point: "vs_main",
entry_point: Some("vs_main"),
buffers: &vertex_buffers,
},
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: "fs_wire",
entry_point: Some("fs_wire"),
targets: &[Some(wgpu::ColorTargetState {
format: config.view_formats[0],
blend: Some(wgpu::BlendState {
Expand Down
2 changes: 1 addition & 1 deletion examples/src/hello_compute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ async fn execute_gpu_inner(
label: None,
layout: None,
module: &cs_module,
entry_point: "main",
entry_point: Some("main"),
});

// Instantiates the bind group, once again specifying the binding of buffers.
Expand Down
4 changes: 2 additions & 2 deletions examples/src/hello_synchronization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ async fn execute(
label: None,
layout: Some(&pipeline_layout),
module: &shaders_module,
entry_point: "patient_main",
entry_point: Some("patient_main"),
});
let hasty_pipeline = device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
label: None,
layout: Some(&pipeline_layout),
module: &shaders_module,
entry_point: "hasty_main",
entry_point: Some("hasty_main"),
});

//----------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions examples/src/hello_triangle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ async fn run(event_loop: EventLoop<()>, window: Window) {
layout: Some(&pipeline_layout),
vertex: wgpu::VertexState {
module: &shader,
entry_point: "vs_main",
entry_point: Some("vs_main"),
buffers: &[],
},
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: "fs_main",
entry_point: Some("fs_main"),
targets: &[Some(swapchain_format.into())],
}),
primitive: wgpu::PrimitiveState::default(),
Expand Down
2 changes: 1 addition & 1 deletion examples/src/hello_workgroups/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ async fn run() {
label: None,
layout: Some(&pipeline_layout),
module: &shader,
entry_point: "main",
entry_point: Some("main"),
});

//----------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions examples/src/mipmap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ impl Example {
layout: None,
vertex: wgpu::VertexState {
module: &shader,
entry_point: "vs_main",
entry_point: Some("vs_main"),
buffers: &[],
},
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: "fs_main",
entry_point: Some("fs_main"),
targets: &[Some(TEXTURE_FORMAT.into())],
}),
primitive: wgpu::PrimitiveState {
Expand Down Expand Up @@ -289,12 +289,12 @@ impl crate::framework::Example for Example {
layout: None,
vertex: wgpu::VertexState {
module: &shader,
entry_point: "vs_main",
entry_point: Some("vs_main"),
buffers: &[],
},
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: "fs_main",
entry_point: Some("fs_main"),
targets: &[Some(config.view_formats[0].into())],
}),
primitive: wgpu::PrimitiveState {
Expand Down
4 changes: 2 additions & 2 deletions examples/src/msaa_line/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl Example {
layout: Some(pipeline_layout),
vertex: wgpu::VertexState {
module: shader,
entry_point: "vs_main",
entry_point: Some("vs_main"),
buffers: &[wgpu::VertexBufferLayout {
array_stride: std::mem::size_of::<Vertex>() as wgpu::BufferAddress,
step_mode: wgpu::VertexStepMode::Vertex,
Expand All @@ -62,7 +62,7 @@ impl Example {
},
fragment: Some(wgpu::FragmentState {
module: shader,
entry_point: "fs_main",
entry_point: Some("fs_main"),
targets: &[Some(config.view_formats[0].into())],
}),
primitive: wgpu::PrimitiveState {
Expand Down
4 changes: 2 additions & 2 deletions examples/src/render_to_texture/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ async fn run(_path: Option<String>) {
layout: None,
vertex: wgpu::VertexState {
module: &shader,
entry_point: "vs_main",
entry_point: Some("vs_main"),
buffers: &[],
},
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: "fs_main",
entry_point: Some("fs_main"),
targets: &[Some(wgpu::TextureFormat::Rgba8UnormSrgb.into())],
}),
primitive: wgpu::PrimitiveState::default(),
Expand Down
2 changes: 1 addition & 1 deletion examples/src/repeated_compute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ impl WgpuContext {
label: None,
layout: Some(&pipeline_layout),
module: &shader,
entry_point: "main",
entry_point: Some("main"),
});

WgpuContext {
Expand Down
8 changes: 4 additions & 4 deletions examples/src/shadow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ impl crate::framework::Example for Example {
layout: Some(&pipeline_layout),
vertex: wgpu::VertexState {
module: &shader,
entry_point: "vs_bake",
entry_point: Some("vs_bake"),
buffers: &[vb_desc.clone()],
},
fragment: None,
Expand Down Expand Up @@ -631,16 +631,16 @@ impl crate::framework::Example for Example {
layout: Some(&pipeline_layout),
vertex: wgpu::VertexState {
module: &shader,
entry_point: "vs_main",
entry_point: Some("vs_main"),
buffers: &[vb_desc],
},
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: if supports_storage_resources {
entry_point: Some(if supports_storage_resources {
"fs_main"
} else {
"fs_main_without_storage"
},
}),
targets: &[Some(config.view_formats[0].into())],
}),
primitive: wgpu::PrimitiveState {
Expand Down
8 changes: 4 additions & 4 deletions examples/src/skybox/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,12 @@ impl crate::framework::Example for Example {
layout: Some(&pipeline_layout),
vertex: wgpu::VertexState {
module: &shader,
entry_point: "vs_sky",
entry_point: Some("vs_sky"),
buffers: &[],
},
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: "fs_sky",
entry_point: Some("fs_sky"),
targets: &[Some(config.view_formats[0].into())],
}),
primitive: wgpu::PrimitiveState {
Expand All @@ -225,7 +225,7 @@ impl crate::framework::Example for Example {
layout: Some(&pipeline_layout),
vertex: wgpu::VertexState {
module: &shader,
entry_point: "vs_entity",
entry_point: Some("vs_entity"),
buffers: &[wgpu::VertexBufferLayout {
array_stride: std::mem::size_of::<Vertex>() as wgpu::BufferAddress,
step_mode: wgpu::VertexStepMode::Vertex,
Expand All @@ -234,7 +234,7 @@ impl crate::framework::Example for Example {
},
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: "fs_entity",
entry_point: Some("fs_entity"),
targets: &[Some(config.view_formats[0].into())],
}),
primitive: wgpu::PrimitiveState {
Expand Down
4 changes: 2 additions & 2 deletions examples/src/srgb_blend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ impl<const SRGB: bool> crate::framework::Example for Example<SRGB> {
layout: Some(&pipeline_layout),
vertex: wgpu::VertexState {
module: &shader,
entry_point: "vs_main",
entry_point: Some("vs_main"),
buffers: &vertex_buffers,
},
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: "fs_main",
entry_point: Some("fs_main"),
targets: &[Some(wgpu::ColorTargetState {
format: config.view_formats[0],
blend: Some(wgpu::BlendState::ALPHA_BLENDING),
Expand Down
Loading

0 comments on commit 8bfc721

Please sign in to comment.