diff options
author | metamuffin <metamuffin@disroot.org> | 2025-05-05 15:09:54 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-05-05 15:09:54 +0200 |
commit | 306f96164784a8cbf405e72fa4364d6523366e95 (patch) | |
tree | 51717fc139871baa438aad806f4923669ae0896c /vgcodec/src/paint.rs | |
parent | 9cc089e2d6e841879e430b01d2f3d92c8820523e (diff) | |
download | video-codec-experiments-306f96164784a8cbf405e72fa4364d6523366e95.tar video-codec-experiments-306f96164784a8cbf405e72fa4364d6523366e95.tar.bz2 video-codec-experiments-306f96164784a8cbf405e72fa4364d6523366e95.tar.zst |
old dir
Diffstat (limited to 'vgcodec/src/paint.rs')
-rw-r--r-- | vgcodec/src/paint.rs | 92 |
1 files changed, 0 insertions, 92 deletions
diff --git a/vgcodec/src/paint.rs b/vgcodec/src/paint.rs deleted file mode 100644 index 33ab572..0000000 --- a/vgcodec/src/paint.rs +++ /dev/null @@ -1,92 +0,0 @@ -use bytemuck::{Pod, Zeroable}; -use std::{borrow::Cow, sync::Arc}; -use wgpu::{util::DeviceExt, BindGroup, Buffer, ComputePipeline, Extent3d, Texture}; - -use crate::app::App; - -pub struct Painter { - app: Arc<App>, - size: Extent3d, - - pipeline: ComputePipeline, - bind_group: BindGroup, - - uniform_buffer: Buffer, -} - -#[repr(C)] -#[derive(Pod, Zeroable, Clone, Copy)] -pub struct PaintUniforms { - pub x: f32, - pub y: f32, - pub rx: f32, - pub ry: f32, - pub r: f32, - pub g: f32, - pub b: f32, -} - -impl Painter { - pub fn new(app: &Arc<App>, extent: Extent3d, texture: &Texture) -> Self { - let App { device, .. } = app.as_ref(); - let cs_module = device.create_shader_module(wgpu::ShaderModuleDescriptor { - label: None, - source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("paint.wgsl"))), - }); - - // let uniform_buffer_size = std::mem::size_of::<PaintUniforms>() as wgpu::BufferAddress; - let uniform_buffer = device.create_buffer_init(&wgpu::util::BufferInitDescriptor { - label: None, - contents: bytemuck::cast_slice(&[PaintUniforms::zeroed()]), - usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST, - }); - - let pipeline = device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor { - label: None, - layout: None, - module: &cs_module, - entry_point: "main", - }); - - let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { - label: None, - layout: &pipeline.get_bind_group_layout(0), - entries: &[ - wgpu::BindGroupEntry { - binding: 0, - resource: wgpu::BindingResource::TextureView( - &texture.create_view(&wgpu::TextureViewDescriptor::default()), - ), - }, - wgpu::BindGroupEntry { - binding: 1, - resource: uniform_buffer.as_entire_binding(), - }, - ], - }); - Self { - app: app.clone(), - size: extent, - pipeline, - uniform_buffer, - bind_group, - } - } - - pub fn run(&self, params: PaintUniforms) { - let App { device, queue, .. } = self.app.as_ref(); - - queue.write_buffer(&self.uniform_buffer, 0, bytemuck::cast_slice(&[params])); - - let mut encoder = - device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None }); - { - let mut cpass = - encoder.begin_compute_pass(&wgpu::ComputePassDescriptor { label: None }); - cpass.set_pipeline(&self.pipeline); - cpass.set_bind_group(0, &self.bind_group, &[]); - cpass.dispatch_workgroups(self.size.width, self.size.height, 1); - } - queue.submit(Some(encoder.finish())); - } -} |