shape_viz_core/renderer/
shaders.rs1use crate::error::Result;
4use bytemuck::{Pod, Zeroable};
5
6use super::vertex::Vertex;
7
8#[repr(C)]
10#[derive(Copy, Clone, Debug, Pod, Zeroable)]
11pub struct ScreenUniforms {
12 pub width: f32,
13 pub height: f32,
14}
15
16pub fn create_render_pipeline(
18 device: &wgpu::Device,
19 bind_group_layout: &wgpu::BindGroupLayout,
20) -> Result<wgpu::RenderPipeline> {
21 let shader_source = include_str!("../shaders/basic.wgsl");
22 let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
23 label: Some("Chart Shader"),
24 source: wgpu::ShaderSource::Wgsl(shader_source.into()),
25 });
26
27 let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
28 label: Some("Chart Pipeline Layout"),
29 bind_group_layouts: &[bind_group_layout],
30 push_constant_ranges: &[],
31 });
32
33 let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
34 label: Some("Chart Pipeline"),
35 layout: Some(&pipeline_layout),
36 vertex: wgpu::VertexState {
37 module: &shader,
38 entry_point: Some("vs_main"),
39 buffers: &[Vertex::desc()],
40 compilation_options: wgpu::PipelineCompilationOptions::default(),
41 },
42 fragment: Some(wgpu::FragmentState {
43 module: &shader,
44 entry_point: Some("fs_main"),
45 targets: &[Some(wgpu::ColorTargetState {
46 format: wgpu::TextureFormat::Rgba8Unorm, blend: Some(wgpu::BlendState::ALPHA_BLENDING),
48 write_mask: wgpu::ColorWrites::ALL,
49 })],
50 compilation_options: wgpu::PipelineCompilationOptions::default(),
51 }),
52 primitive: wgpu::PrimitiveState {
53 topology: wgpu::PrimitiveTopology::TriangleList,
54 strip_index_format: None,
55 front_face: wgpu::FrontFace::Ccw,
56 cull_mode: None,
57 unclipped_depth: false,
58 polygon_mode: wgpu::PolygonMode::Fill,
59 conservative: false,
60 },
61 depth_stencil: None,
62 multisample: wgpu::MultisampleState::default(),
63 multiview: None,
64 cache: None,
65 });
66
67 Ok(render_pipeline)
68}