Skip to content

Commit

Permalink
Drop pipeline builder (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
PolyMeilex authored May 14, 2024
1 parent 79add14 commit b1bf5c7
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 80 deletions.
22 changes: 11 additions & 11 deletions neothesia-core/src/render/background_animation/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::time::Duration;

use wgpu_jumpstart::{wgpu, Gpu, RenderPipelineBuilder, Shape, Uniform};
use wgpu_jumpstart::{wgpu, Gpu, Shape, Uniform};

use bytemuck::{Pod, Zeroable};

Expand Down Expand Up @@ -39,16 +39,16 @@ impl BgPipeline {

let target = wgpu_jumpstart::default_color_target_state(gpu.texture_format);

let render_pipeline = wgpu::RenderPipelineDescriptor::builder(
render_pipeline_layout,
wgpu::VertexState {
module: &shader,
entry_point: "vs_main",
buffers: &[Shape::layout()],
},
)
.fragment("fs_main", &shader, &[Some(target)])
.create_render_pipeline(&gpu.device);
let render_pipeline = gpu
.device
.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
layout: Some(render_pipeline_layout),
fragment: Some(wgpu_jumpstart::default_fragment(&shader, &[Some(target)])),
..wgpu_jumpstart::default_render_pipeline(wgpu_jumpstart::default_vertex(
&shader,
&[Shape::layout()],
))
});

let fullscreen_quad = Shape::new_fullscreen_quad(&gpu.device);

Expand Down
24 changes: 11 additions & 13 deletions neothesia-core/src/render/quad/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
mod instance_data;
pub use instance_data::QuadInstance;

use wgpu_jumpstart::{
wgpu, Gpu, Instances, RenderPipelineBuilder, Shape, TransformUniform, Uniform,
};
use wgpu_jumpstart::{wgpu, Gpu, Instances, Shape, TransformUniform, Uniform};

pub struct QuadPipeline {
render_pipeline: wgpu::RenderPipeline,
Expand Down Expand Up @@ -34,16 +32,16 @@ impl<'a> QuadPipeline {

let target = wgpu_jumpstart::default_color_target_state(gpu.texture_format);

let render_pipeline = wgpu::RenderPipelineDescriptor::builder(
&render_pipeline_layout,
wgpu::VertexState {
module: &shader,
entry_point: "vs_main",
buffers: &[Shape::layout(), QuadInstance::layout(&ri_attrs)],
},
)
.fragment("fs_main", &shader, &[Some(target)])
.create_render_pipeline(&gpu.device);
let render_pipeline = gpu
.device
.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
layout: Some(&render_pipeline_layout),
fragment: Some(wgpu_jumpstart::default_fragment(&shader, &[Some(target)])),
..wgpu_jumpstart::default_render_pipeline(wgpu_jumpstart::default_vertex(
&shader,
&[Shape::layout(), QuadInstance::layout(&ri_attrs)],
))
});

let quad = Shape::new_quad(&gpu.device);
let instances = Instances::new(&gpu.device, 100_000);
Expand Down
26 changes: 12 additions & 14 deletions neothesia-core/src/render/waterfall/pipeline/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ mod instance_data;

pub use instance_data::NoteInstance;

use wgpu_jumpstart::{
wgpu, Gpu, Instances, RenderPipelineBuilder, Shape, TransformUniform, Uniform,
};
use wgpu_jumpstart::{wgpu, Gpu, Instances, Shape, TransformUniform, Uniform};

use bytemuck::{Pod, Zeroable};

Expand Down Expand Up @@ -39,7 +37,7 @@ impl<'a> WaterfallPipeline {
);

let render_pipeline_layout =
&gpu.device
gpu.device
.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: None,
bind_group_layouts: &[
Expand All @@ -53,16 +51,16 @@ impl<'a> WaterfallPipeline {

let target = wgpu_jumpstart::default_color_target_state(gpu.texture_format);

let render_pipeline = wgpu::RenderPipelineDescriptor::builder(
render_pipeline_layout,
wgpu::VertexState {
module: &shader,
entry_point: "vs_main",
buffers: &[Shape::layout(), NoteInstance::layout(&ni_attrs)],
},
)
.fragment("fs_main", &shader, &[Some(target)])
.create_render_pipeline(&gpu.device);
let render_pipeline = gpu
.device
.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
layout: Some(&render_pipeline_layout),
fragment: Some(wgpu_jumpstart::default_fragment(&shader, &[Some(target)])),
..wgpu_jumpstart::default_render_pipeline(wgpu_jumpstart::default_vertex(
&shader,
&[Shape::layout(), NoteInstance::layout(&ni_attrs)],
))
});

let quad = Shape::new_quad(&gpu.device);

Expand Down
4 changes: 3 additions & 1 deletion wgpu-jumpstart/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ pub use {
color::Color,
gpu::{default_backends, Gpu, Surface},
instances::Instances,
render_pipeline_builder::{default_color_target_state, RenderPipelineBuilder},
render_pipeline_builder::{
default_color_target_state, default_fragment, default_render_pipeline, default_vertex,
},
shape::Shape,
transform_uniform::TransformUniform,
uniform::Uniform,
Expand Down
69 changes: 28 additions & 41 deletions wgpu-jumpstart/src/render_pipeline_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,50 +17,37 @@ pub fn default_color_target_state(texture_format: wgpu::TextureFormat) -> wgpu::
}
}

pub trait RenderPipelineBuilder<'a> {
fn builder(layout: &'a wgpu::PipelineLayout, vertex: wgpu::VertexState<'a>) -> Self;
fn fragment(
self,
entry_point: &'a str,
fragment_module: &'a wgpu::ShaderModule,
targets: &'a [Option<wgpu::ColorTargetState>],
) -> Self;
fn create_render_pipeline(&self, device: &wgpu::Device) -> wgpu::RenderPipeline;
}

impl<'a> RenderPipelineBuilder<'a> for wgpu::RenderPipelineDescriptor<'a> {
fn builder(layout: &'a wgpu::PipelineLayout, vertex: wgpu::VertexState<'a>) -> Self {
wgpu::RenderPipelineDescriptor {
label: None,
layout: Some(layout),
vertex,
fragment: None,
primitive: wgpu::PrimitiveState::default(),
depth_stencil: None,
multisample: wgpu::MultisampleState {
count: 1,
mask: !0,
alpha_to_coverage_enabled: false,
},
multiview: None,
}
pub fn default_fragment<'a>(
module: &'a wgpu::ShaderModule,
targets: &'a [Option<wgpu::ColorTargetState>],
) -> wgpu::FragmentState<'a> {
wgpu::FragmentState {
module,
entry_point: "fs_main",
targets,
}
}

fn fragment(
mut self,
entry_point: &'a str,
fragment_module: &'a wgpu::ShaderModule,
targets: &'a [Option<wgpu::ColorTargetState>],
) -> Self {
self.fragment = Some(wgpu::FragmentState {
module: fragment_module,
entry_point,
targets,
});
self
pub fn default_vertex<'a>(
module: &'a wgpu::ShaderModule,
buffers: &'a [wgpu::VertexBufferLayout<'a>],
) -> wgpu::VertexState<'a> {
wgpu::VertexState {
module,
entry_point: "vs_main",
buffers,
}
}

fn create_render_pipeline(&self, device: &wgpu::Device) -> wgpu::RenderPipeline {
device.create_render_pipeline(self)
pub fn default_render_pipeline(vertex: wgpu::VertexState) -> wgpu::RenderPipelineDescriptor {
wgpu::RenderPipelineDescriptor {
label: None,
layout: None,
vertex,
fragment: None,
primitive: wgpu::PrimitiveState::default(),
depth_stencil: None,
multisample: wgpu::MultisampleState::default(),
multiview: None,
}
}

0 comments on commit b1bf5c7

Please sign in to comment.