diff options
Diffstat (limited to 'src/gpu')
| -rw-r--r-- | src/gpu/demo_effects.h | 34 | ||||
| -rw-r--r-- | src/gpu/effect.cc | 2 | ||||
| -rw-r--r-- | src/gpu/effect.h | 10 | ||||
| -rw-r--r-- | src/gpu/effects/chroma_aberration_effect.cc | 6 | ||||
| -rw-r--r-- | src/gpu/effects/distort_effect.cc | 6 | ||||
| -rw-r--r-- | src/gpu/effects/gaussian_blur_effect.cc | 6 | ||||
| -rw-r--r-- | src/gpu/effects/heptagon_effect.cc | 6 | ||||
| -rw-r--r-- | src/gpu/effects/moving_ellipse_effect.cc | 6 | ||||
| -rw-r--r-- | src/gpu/effects/particle_spray_effect.cc | 10 | ||||
| -rw-r--r-- | src/gpu/effects/particles_effect.cc | 10 | ||||
| -rw-r--r-- | src/gpu/effects/passthrough_effect.cc | 8 | ||||
| -rw-r--r-- | src/gpu/effects/solarize_effect.cc | 6 |
12 files changed, 44 insertions, 66 deletions
diff --git a/src/gpu/demo_effects.h b/src/gpu/demo_effects.h index e94f015..2d495f3 100644 --- a/src/gpu/demo_effects.h +++ b/src/gpu/demo_effects.h @@ -24,9 +24,7 @@ class HeptagonEffect : public Effect { float intensity, float aspect_ratio) override; private: - WGPUQueue queue_; RenderPass pass_; - GpuBuffer uniforms_; }; class ParticlesEffect : public Effect { @@ -38,21 +36,15 @@ class ParticlesEffect : public Effect { float intensity, float aspect_ratio) override; private: - WGPUQueue queue_; ComputePass compute_pass_; RenderPass render_pass_; GpuBuffer particles_buffer_; - GpuBuffer uniforms_; }; class PassthroughEffect : public PostProcessEffect { public: - PassthroughEffect(WGPUDevice device, WGPUTextureFormat format); + PassthroughEffect(WGPUDevice device, WGPUQueue queue, WGPUTextureFormat format); void update_bind_group(WGPUTextureView input_view) override; - - private: - WGPUDevice device_; - GpuBuffer uniforms_; }; class MovingEllipseEffect : public Effect { @@ -63,9 +55,7 @@ class MovingEllipseEffect : public Effect { float intensity, float aspect_ratio) override; private: - WGPUQueue queue_; RenderPass pass_; - GpuBuffer uniforms_; }; class ParticleSprayEffect : public Effect { @@ -78,11 +68,9 @@ class ParticleSprayEffect : public Effect { float intensity, float aspect_ratio) override; private: - WGPUQueue queue_; ComputePass compute_pass_; RenderPass render_pass_; GpuBuffer particles_buffer_; - GpuBuffer uniforms_; }; class GaussianBlurEffect : public PostProcessEffect { @@ -92,11 +80,6 @@ class GaussianBlurEffect : public PostProcessEffect { void render(WGPURenderPassEncoder pass, float time, float beat, float intensity, float aspect_ratio) override; void update_bind_group(WGPUTextureView input_view) override; - - private: - WGPUDevice device_; - WGPUQueue queue_; - GpuBuffer uniforms_; }; class SolarizeEffect : public PostProcessEffect { @@ -105,11 +88,6 @@ class SolarizeEffect : public PostProcessEffect { void render(WGPURenderPassEncoder pass, float time, float beat, float intensity, float aspect_ratio) override; void update_bind_group(WGPUTextureView input_view) override; - - private: - WGPUDevice device_; - WGPUQueue queue_; - GpuBuffer uniforms_; }; class DistortEffect : public PostProcessEffect { @@ -118,11 +96,6 @@ class DistortEffect : public PostProcessEffect { void render(WGPURenderPassEncoder pass, float time, float beat, float intensity, float aspect_ratio) override; void update_bind_group(WGPUTextureView input_view) override; - - private: - WGPUDevice device_; - WGPUQueue queue_; - GpuBuffer uniforms_; }; class ChromaAberrationEffect : public PostProcessEffect { @@ -132,11 +105,6 @@ class ChromaAberrationEffect : public PostProcessEffect { void render(WGPURenderPassEncoder pass, float time, float beat, float intensity, float aspect_ratio) override; void update_bind_group(WGPUTextureView input_view) override; - - private: - WGPUDevice device_; - WGPUQueue queue_; - GpuBuffer uniforms_; }; // Auto-generated function to populate the timeline diff --git a/src/gpu/effect.cc b/src/gpu/effect.cc index 64bd053..997946c 100644 --- a/src/gpu/effect.cc +++ b/src/gpu/effect.cc @@ -128,7 +128,7 @@ void MainSequence::init(WGPUDevice d, WGPUQueue q, WGPUTextureFormat f, format = f; create_framebuffers(width, height); - passthrough_effect_ = std::make_unique<PassthroughEffect>(device, format); + passthrough_effect_ = std::make_unique<PassthroughEffect>(device, queue, format); for (ActiveSequence& entry : sequences_) { entry.seq->init(this); diff --git a/src/gpu/effect.h b/src/gpu/effect.h index ee90fa4..488e92e 100644 --- a/src/gpu/effect.h +++ b/src/gpu/effect.h @@ -1,4 +1,5 @@ #pragma once +#include "gpu/gpu.h" #include <algorithm> #include <memory> #include <vector> @@ -14,6 +15,8 @@ class PostProcessEffect; class Effect { public: + Effect(WGPUDevice device, WGPUQueue queue) + : device_(device), queue_(queue) {} virtual ~Effect() = default; virtual void init(MainSequence* demo) { (void)demo; @@ -36,10 +39,17 @@ class Effect { virtual bool is_post_process() const { return false; } + + protected: + WGPUDevice device_; + WGPUQueue queue_; + GpuBuffer uniforms_; }; class PostProcessEffect : public Effect { public: + PostProcessEffect(WGPUDevice device, WGPUQueue queue) + : Effect(device, queue) {} bool is_post_process() const override { return true; } diff --git a/src/gpu/effects/chroma_aberration_effect.cc b/src/gpu/effects/chroma_aberration_effect.cc index 5acc1f4..ef9e963 100644 --- a/src/gpu/effects/chroma_aberration_effect.cc +++ b/src/gpu/effects/chroma_aberration_effect.cc @@ -8,11 +8,11 @@ ChromaAberrationEffect::ChromaAberrationEffect(WGPUDevice device, WGPUQueue queue, WGPUTextureFormat format) - : device_(device), queue_(queue) { + : PostProcessEffect(device, queue) { uniforms_ = - gpu_create_buffer(device, sizeof(float) * 4, + gpu_create_buffer(device_, sizeof(float) * 4, WGPUBufferUsage_Uniform | WGPUBufferUsage_CopyDst); - pipeline_ = create_post_process_pipeline(device, format, + pipeline_ = create_post_process_pipeline(device_, format, chroma_aberration_shader_wgsl); } void ChromaAberrationEffect::render(WGPURenderPassEncoder pass, float t, diff --git a/src/gpu/effects/distort_effect.cc b/src/gpu/effects/distort_effect.cc index 994ee34..1f2b8fc 100644 --- a/src/gpu/effects/distort_effect.cc +++ b/src/gpu/effects/distort_effect.cc @@ -7,11 +7,11 @@ // --- DistortEffect --- DistortEffect::DistortEffect(WGPUDevice device, WGPUQueue queue, WGPUTextureFormat format) - : device_(device), queue_(queue) { + : PostProcessEffect(device, queue) { uniforms_ = - gpu_create_buffer(device, sizeof(float) * 4, + gpu_create_buffer(device_, sizeof(float) * 4, WGPUBufferUsage_Uniform | WGPUBufferUsage_CopyDst); - pipeline_ = create_post_process_pipeline(device, format, distort_shader_wgsl); + pipeline_ = create_post_process_pipeline(device_, format, distort_shader_wgsl); } void DistortEffect::render(WGPURenderPassEncoder pass, float t, float b, float i, float a) { diff --git a/src/gpu/effects/gaussian_blur_effect.cc b/src/gpu/effects/gaussian_blur_effect.cc index 0b55bb0..28f5b97 100644 --- a/src/gpu/effects/gaussian_blur_effect.cc +++ b/src/gpu/effects/gaussian_blur_effect.cc @@ -7,12 +7,12 @@ // --- GaussianBlurEffect --- GaussianBlurEffect::GaussianBlurEffect(WGPUDevice device, WGPUQueue queue, WGPUTextureFormat format) - : device_(device), queue_(queue) { + : PostProcessEffect(device, queue) { uniforms_ = - gpu_create_buffer(device, sizeof(float) * 4, + gpu_create_buffer(device_, sizeof(float) * 4, WGPUBufferUsage_Uniform | WGPUBufferUsage_CopyDst); pipeline_ = - create_post_process_pipeline(device, format, gaussian_blur_shader_wgsl); + create_post_process_pipeline(device_, format, gaussian_blur_shader_wgsl); } void GaussianBlurEffect::render(WGPURenderPassEncoder pass, float t, float b, float i, float a) { diff --git a/src/gpu/effects/heptagon_effect.cc b/src/gpu/effects/heptagon_effect.cc index 321b9d1..64e4b47 100644 --- a/src/gpu/effects/heptagon_effect.cc +++ b/src/gpu/effects/heptagon_effect.cc @@ -7,12 +7,12 @@ // --- HeptagonEffect --- HeptagonEffect::HeptagonEffect(WGPUDevice device, WGPUQueue queue, WGPUTextureFormat format) - : queue_(queue) { + : Effect(device, queue) { uniforms_ = - gpu_create_buffer(device, sizeof(float) * 4, + gpu_create_buffer(device_, sizeof(float) * 4, WGPUBufferUsage_Uniform | WGPUBufferUsage_CopyDst); ResourceBinding bindings[] = {{uniforms_, WGPUBufferBindingType_Uniform}}; - pass_ = gpu_create_render_pass(device, format, main_shader_wgsl, bindings, 1); + pass_ = gpu_create_render_pass(device_, format, main_shader_wgsl, bindings, 1); pass_.vertex_count = 21; } void HeptagonEffect::render(WGPURenderPassEncoder pass, float t, float b, diff --git a/src/gpu/effects/moving_ellipse_effect.cc b/src/gpu/effects/moving_ellipse_effect.cc index 60fc825..b46eecd 100644 --- a/src/gpu/effects/moving_ellipse_effect.cc +++ b/src/gpu/effects/moving_ellipse_effect.cc @@ -7,13 +7,13 @@ // --- MovingEllipseEffect --- MovingEllipseEffect::MovingEllipseEffect(WGPUDevice device, WGPUQueue queue, WGPUTextureFormat format) - : queue_(queue) { + : Effect(device, queue) { uniforms_ = - gpu_create_buffer(device, sizeof(float) * 4, + gpu_create_buffer(device_, sizeof(float) * 4, WGPUBufferUsage_Uniform | WGPUBufferUsage_CopyDst); ResourceBinding bindings[] = {{uniforms_, WGPUBufferBindingType_Uniform}}; pass_ = - gpu_create_render_pass(device, format, ellipse_shader_wgsl, bindings, 1); + gpu_create_render_pass(device_, format, ellipse_shader_wgsl, bindings, 1); pass_.vertex_count = 3; } void MovingEllipseEffect::render(WGPURenderPassEncoder pass, float t, float b, diff --git a/src/gpu/effects/particle_spray_effect.cc b/src/gpu/effects/particle_spray_effect.cc index a5e4292..b5c5f42 100644 --- a/src/gpu/effects/particle_spray_effect.cc +++ b/src/gpu/effects/particle_spray_effect.cc @@ -8,26 +8,26 @@ // --- ParticleSprayEffect --- ParticleSprayEffect::ParticleSprayEffect(WGPUDevice device, WGPUQueue queue, WGPUTextureFormat format) - : queue_(queue) { + : Effect(device, queue) { uniforms_ = - gpu_create_buffer(device, sizeof(float) * 4, + gpu_create_buffer(device_, sizeof(float) * 4, WGPUBufferUsage_Uniform | WGPUBufferUsage_CopyDst); std::vector<Particle> init_p(NUM_PARTICLES); for (Particle& p : init_p) p.pos[3] = 0.0f; particles_buffer_ = gpu_create_buffer( - device, sizeof(Particle) * NUM_PARTICLES, + device_, sizeof(Particle) * NUM_PARTICLES, WGPUBufferUsage_Storage | WGPUBufferUsage_Vertex, init_p.data()); ResourceBinding cb[] = {{particles_buffer_, WGPUBufferBindingType_Storage}, {uniforms_, WGPUBufferBindingType_Uniform}}; compute_pass_ = - gpu_create_compute_pass(device, particle_spray_compute_wgsl, cb, 2); + gpu_create_compute_pass(device_, particle_spray_compute_wgsl, cb, 2); compute_pass_.workgroup_size_x = (NUM_PARTICLES + 63) / 64; ResourceBinding rb[] = { {particles_buffer_, WGPUBufferBindingType_ReadOnlyStorage}, {uniforms_, WGPUBufferBindingType_Uniform}}; render_pass_ = - gpu_create_render_pass(device, format, particle_render_wgsl, rb, 2); + gpu_create_render_pass(device_, format, particle_render_wgsl, rb, 2); render_pass_.vertex_count = 6; render_pass_.instance_count = NUM_PARTICLES; } diff --git a/src/gpu/effects/particles_effect.cc b/src/gpu/effects/particles_effect.cc index 545fdfb..f2ef96b 100644 --- a/src/gpu/effects/particles_effect.cc +++ b/src/gpu/effects/particles_effect.cc @@ -8,23 +8,23 @@ // --- ParticlesEffect --- ParticlesEffect::ParticlesEffect(WGPUDevice device, WGPUQueue queue, WGPUTextureFormat format) - : queue_(queue) { + : Effect(device, queue) { uniforms_ = - gpu_create_buffer(device, sizeof(float) * 4, + gpu_create_buffer(device_, sizeof(float) * 4, WGPUBufferUsage_Uniform | WGPUBufferUsage_CopyDst); std::vector<Particle> init_p(NUM_PARTICLES); particles_buffer_ = gpu_create_buffer( - device, sizeof(Particle) * NUM_PARTICLES, + device_, sizeof(Particle) * NUM_PARTICLES, WGPUBufferUsage_Storage | WGPUBufferUsage_Vertex, init_p.data()); ResourceBinding cb[] = {{particles_buffer_, WGPUBufferBindingType_Storage}, {uniforms_, WGPUBufferBindingType_Uniform}}; - compute_pass_ = gpu_create_compute_pass(device, particle_compute_wgsl, cb, 2); + compute_pass_ = gpu_create_compute_pass(device_, particle_compute_wgsl, cb, 2); compute_pass_.workgroup_size_x = (NUM_PARTICLES + 63) / 64; ResourceBinding rb[] = { {particles_buffer_, WGPUBufferBindingType_ReadOnlyStorage}, {uniforms_, WGPUBufferBindingType_Uniform}}; render_pass_ = - gpu_create_render_pass(device, format, particle_render_wgsl, rb, 2); + gpu_create_render_pass(device_, format, particle_render_wgsl, rb, 2); render_pass_.vertex_count = 6; render_pass_.instance_count = NUM_PARTICLES; } diff --git a/src/gpu/effects/passthrough_effect.cc b/src/gpu/effects/passthrough_effect.cc index a00f661..cb92ba1 100644 --- a/src/gpu/effects/passthrough_effect.cc +++ b/src/gpu/effects/passthrough_effect.cc @@ -5,14 +5,14 @@ #include "gpu/gpu.h" // --- PassthroughEffect --- -PassthroughEffect::PassthroughEffect(WGPUDevice device, +PassthroughEffect::PassthroughEffect(WGPUDevice device, WGPUQueue queue, WGPUTextureFormat format) - : device_(device) { + : PostProcessEffect(device, queue) { uniforms_ = - gpu_create_buffer(device, sizeof(float) * 4, + gpu_create_buffer(device_, sizeof(float) * 4, WGPUBufferUsage_Uniform | WGPUBufferUsage_CopyDst); pipeline_ = - create_post_process_pipeline(device, format, passthrough_shader_wgsl); + create_post_process_pipeline(device_, format, passthrough_shader_wgsl); } void PassthroughEffect::update_bind_group(WGPUTextureView input_view) { pp_update_bind_group(device_, pipeline_, &bind_group_, input_view, uniforms_); diff --git a/src/gpu/effects/solarize_effect.cc b/src/gpu/effects/solarize_effect.cc index f7c09de..f8a7f33 100644 --- a/src/gpu/effects/solarize_effect.cc +++ b/src/gpu/effects/solarize_effect.cc @@ -7,12 +7,12 @@ // --- SolarizeEffect --- SolarizeEffect::SolarizeEffect(WGPUDevice device, WGPUQueue queue, WGPUTextureFormat format) - : device_(device), queue_(queue) { + : PostProcessEffect(device, queue) { uniforms_ = - gpu_create_buffer(device, sizeof(float) * 4, + gpu_create_buffer(device_, sizeof(float) * 4, WGPUBufferUsage_Uniform | WGPUBufferUsage_CopyDst); pipeline_ = - create_post_process_pipeline(device, format, solarize_shader_wgsl); + create_post_process_pipeline(device_, format, solarize_shader_wgsl); } void SolarizeEffect::render(WGPURenderPassEncoder pass, float t, float b, float i, float a) { |
