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 /old/vgcodec/src/app.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 'old/vgcodec/src/app.rs')
-rw-r--r-- | old/vgcodec/src/app.rs | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/old/vgcodec/src/app.rs b/old/vgcodec/src/app.rs new file mode 100644 index 0000000..b51284c --- /dev/null +++ b/old/vgcodec/src/app.rs @@ -0,0 +1,59 @@ +use std::sync::Arc; + +use wgpu::{Adapter, Device, Extent3d, ImageCopyTexture, Instance, Origin3d, Queue, Texture}; + +pub struct App { + pub instance: Instance, + pub device: Device, + pub adapter: Adapter, + pub queue: Queue, +} + +impl App { + pub async fn new() -> Arc<Self> { + let instance = wgpu::Instance::new(wgpu::Backends::all()); + let adapter = instance + .request_adapter(&wgpu::RequestAdapterOptions::default()) + .await + .unwrap(); + let (device, queue) = adapter + .request_device( + &wgpu::DeviceDescriptor { + label: None, + features: wgpu::Features::empty(), + limits: wgpu::Limits::downlevel_defaults(), + }, + None, + ) + .await + .unwrap(); + Arc::new(Self { + adapter, + device, + instance, + queue, + }) + } + + pub fn copy_texture(&self, source: &Texture, destination: &Texture, size: Extent3d) { + let mut encoder = self + .device + .create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None }); + encoder.copy_texture_to_texture( + ImageCopyTexture { + aspect: wgpu::TextureAspect::All, + mip_level: 0, + origin: Origin3d::ZERO, + texture: source, + }, + ImageCopyTexture { + aspect: wgpu::TextureAspect::All, + mip_level: 0, + origin: Origin3d::ZERO, + texture: destination, + }, + size, + ); + self.queue.submit(Some(encoder.finish())); + } +} |