Compare commits
No commits in common. "ee5308ac237d3b980184f98c5ffd194b4ad294c8" and "ab76a63256cd399a65a434976a8bdc79c20e0604" have entirely different histories.
ee5308ac23
...
ab76a63256
|
@ -15,7 +15,12 @@ pub struct BulkBufferBuilder<'a> {
|
|||
|
||||
impl<'a> BulkBufferBuilder<'a> {
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
Self {
|
||||
order: vec![],
|
||||
init_descriptors: vec![],
|
||||
descriptors: vec![],
|
||||
current_usage: wgpu::BufferUsages::UNIFORM,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_usage(mut self, usage: wgpu::BufferUsages) -> Self {
|
||||
|
@ -69,17 +74,6 @@ impl<'a> BulkBufferBuilder<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> Default for BulkBufferBuilder<'a> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
order: vec![],
|
||||
init_descriptors: vec![],
|
||||
descriptors: vec![],
|
||||
current_usage: wgpu::BufferUsages::UNIFORM,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait BufferExt {
|
||||
fn get_mapped_range<S: RangeBounds<wgpu::BufferAddress>, T: bytemuck::Pod>(
|
||||
&self,
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
mod bind_group;
|
||||
mod buffer;
|
||||
mod context;
|
||||
mod pipeline;
|
||||
mod texture;
|
||||
|
||||
pub use self::{
|
||||
bind_group::{BindGroupBuilder, BindGroupLayoutBuilder},
|
||||
buffer::{BufferExt, BulkBufferBuilder},
|
||||
context::{Context, ContextBuilder},
|
||||
pipeline::{ComputePipelineBuilder, RenderPipelineBuilder},
|
||||
texture::{Texture, TextureBuilder},
|
||||
};
|
||||
|
||||
|
|
159
src/pipeline.rs
159
src/pipeline.rs
|
@ -1,159 +0,0 @@
|
|||
use std::num::NonZeroU32;
|
||||
|
||||
use crate::Context;
|
||||
|
||||
pub struct RenderPipelineBuilder<'a> {
|
||||
label: &'a str,
|
||||
shader: &'a wgpu::ShaderModule,
|
||||
layout_descriptor: Option<wgpu::PipelineLayoutDescriptor<'a>>,
|
||||
vertex: wgpu::VertexState<'a>,
|
||||
fragment: Option<wgpu::FragmentState<'a>>,
|
||||
primitive: wgpu::PrimitiveState,
|
||||
depth_stencil: Option<wgpu::DepthStencilState>,
|
||||
multisample: wgpu::MultisampleState,
|
||||
multiview: Option<NonZeroU32>,
|
||||
}
|
||||
|
||||
impl<'a> RenderPipelineBuilder<'a> {
|
||||
pub fn new(label: &'a str, shader: &'a wgpu::ShaderModule) -> Self {
|
||||
Self {
|
||||
label,
|
||||
shader,
|
||||
layout_descriptor: None,
|
||||
vertex: wgpu::VertexState {
|
||||
module: shader,
|
||||
entry_point: "vertex",
|
||||
buffers: &[],
|
||||
},
|
||||
fragment: None,
|
||||
primitive: wgpu::PrimitiveState::default(),
|
||||
depth_stencil: None,
|
||||
multisample: wgpu::MultisampleState::default(),
|
||||
multiview: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_layout(
|
||||
mut self,
|
||||
label: &'a str,
|
||||
bind_group_layouts: &'a [&wgpu::BindGroupLayout],
|
||||
push_constant_ranges: &'a [wgpu::PushConstantRange],
|
||||
) -> Self {
|
||||
let layout_descriptor = wgpu::PipelineLayoutDescriptor {
|
||||
label: Some(label),
|
||||
bind_group_layouts,
|
||||
push_constant_ranges,
|
||||
};
|
||||
|
||||
self.layout_descriptor = Some(layout_descriptor);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_vertex_buffers(mut self, buffers: &'a [wgpu::VertexBufferLayout<'a>]) -> Self {
|
||||
self.vertex.buffers = buffers;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_fragment_targets(mut self, targets: &'a [Option<wgpu::ColorTargetState>]) -> Self {
|
||||
self.fragment = Some(wgpu::FragmentState {
|
||||
module: self.shader,
|
||||
entry_point: "fragment",
|
||||
targets,
|
||||
});
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_primitive(mut self, primitive: wgpu::PrimitiveState) -> Self {
|
||||
self.primitive = primitive;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_depth_stencil(mut self, depth_stencil: wgpu::DepthStencilState) -> Self {
|
||||
self.depth_stencil = Some(depth_stencil);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_multisample(mut self, multisample: wgpu::MultisampleState) -> Self {
|
||||
self.multisample = multisample;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_multiview(mut self, multiview: NonZeroU32) -> Self {
|
||||
self.multiview = Some(multiview);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn build(self, context: &Context) -> wgpu::RenderPipeline {
|
||||
let raw_layout;
|
||||
let layout = if let Some(descriptor) = self.layout_descriptor {
|
||||
raw_layout = context.device.create_pipeline_layout(&descriptor);
|
||||
Some(&raw_layout)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
context
|
||||
.device
|
||||
.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
||||
label: Some(self.label),
|
||||
layout,
|
||||
vertex: self.vertex,
|
||||
fragment: self.fragment,
|
||||
primitive: self.primitive,
|
||||
depth_stencil: self.depth_stencil,
|
||||
multisample: self.multisample,
|
||||
multiview: self.multiview,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ComputePipelineBuilder<'a> {
|
||||
label: &'a str,
|
||||
shader: &'a wgpu::ShaderModule,
|
||||
layout_descriptor: Option<wgpu::PipelineLayoutDescriptor<'a>>,
|
||||
}
|
||||
|
||||
impl<'a> ComputePipelineBuilder<'a> {
|
||||
pub fn new(label: &'a str, shader: &'a wgpu::ShaderModule) -> Self {
|
||||
Self {
|
||||
label,
|
||||
shader,
|
||||
layout_descriptor: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_layout(
|
||||
mut self,
|
||||
label: &'a str,
|
||||
bind_group_layouts: &'a [&wgpu::BindGroupLayout],
|
||||
push_constant_ranges: &'a [wgpu::PushConstantRange],
|
||||
) -> Self {
|
||||
let layout_descriptor = wgpu::PipelineLayoutDescriptor {
|
||||
label: Some(label),
|
||||
bind_group_layouts,
|
||||
push_constant_ranges,
|
||||
};
|
||||
|
||||
self.layout_descriptor = Some(layout_descriptor);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn build(self, context: &Context) -> wgpu::ComputePipeline {
|
||||
let raw_layout;
|
||||
let layout = if let Some(descriptor) = self.layout_descriptor {
|
||||
raw_layout = context.device.create_pipeline_layout(&descriptor);
|
||||
Some(&raw_layout)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
context
|
||||
.device
|
||||
.create_compute_pipeline(&wgpu::ComputePipelineDescriptor {
|
||||
label: Some(self.label),
|
||||
layout,
|
||||
module: self.shader,
|
||||
entry_point: "compute",
|
||||
})
|
||||
}
|
||||
}
|
|
@ -44,14 +44,16 @@ impl Default for TextureAttributes {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
#[derive(Debug)]
|
||||
pub struct TextureBuilder {
|
||||
pub attributes: TextureAttributes,
|
||||
}
|
||||
|
||||
impl TextureBuilder {
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
Self {
|
||||
attributes: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
|
Loading…
Reference in New Issue