summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/3d/renderer_draw.cc2
-rw-r--r--src/3d/renderer_pipelines.cc6
-rw-r--r--src/3d/scene_loader.cc57
-rw-r--r--src/3d/scene_loader.h17
-rw-r--r--src/app/main.cc11
-rw-r--r--src/app/test_demo.cc2
-rw-r--r--src/audio/audio.cc3
-rw-r--r--src/audio/backend/miniaudio_backend.cc8
-rw-r--r--src/audio/backend/miniaudio_backend.h2
-rw-r--r--src/audio/tracker.cc3
-rw-r--r--src/effects/flash_effect.cc54
-rw-r--r--src/effects/flash_effect.h13
-rw-r--r--src/effects/gaussian_blur_effect.cc34
-rw-r--r--src/effects/gaussian_blur_effect.h11
-rw-r--r--src/effects/heptagon_effect.cc61
-rw-r--r--src/effects/heptagon_effect.h10
-rw-r--r--src/effects/hybrid3_d_effect.cc70
-rw-r--r--src/effects/hybrid3_d_effect.h13
-rw-r--r--src/effects/particles_effect.cc57
-rw-r--r--src/effects/particles_effect.h12
-rw-r--r--src/effects/passthrough_effect.cc41
-rw-r--r--src/effects/passthrough_effect.h7
-rw-r--r--src/effects/peak_meter_effect.cc36
-rw-r--r--src/effects/peak_meter_effect.h13
-rw-r--r--src/effects/placeholder_effect.cc43
-rw-r--r--src/effects/placeholder_effect.h9
-rw-r--r--src/effects/rotating_cube_effect.cc68
-rw-r--r--src/effects/rotating_cube_effect.h13
-rw-r--r--src/effects/shaders.cc (renamed from src/gpu/shaders.cc)104
-rw-r--r--src/effects/shaders.h25
-rw-r--r--src/gpu/bind_group_builder.h3
-rw-r--r--src/gpu/demo_effects.cc2
-rw-r--r--src/gpu/demo_effects.h16
-rw-r--r--src/gpu/effect.cc50
-rw-r--r--src/gpu/effect.h17
-rw-r--r--src/gpu/gpu.cc2
-rw-r--r--src/gpu/gpu.h29
-rw-r--r--src/gpu/gpu_headless.cc (renamed from src/gpu/headless_gpu.cc)0
-rw-r--r--src/gpu/gpu_stub.cc (renamed from src/gpu/stub_gpu.cc)0
-rw-r--r--src/gpu/post_process_helper.cc6
-rw-r--r--src/gpu/post_process_helper.h15
-rw-r--r--src/gpu/sdf_effect.h9
-rw-r--r--src/gpu/sequence.cc56
-rw-r--r--src/gpu/sequence.h36
-rw-r--r--src/gpu/shader_composer.h7
-rw-r--r--src/gpu/shaders.h39
-rw-r--r--src/gpu/texture_manager.cc21
-rw-r--r--src/gpu/texture_readback.cc36
-rw-r--r--src/gpu/uniform_helper.h7
-rw-r--r--src/tests/3d/test_3d_physics.cc2
-rw-r--r--src/tests/3d/test_3d_render.cc2
-rw-r--r--src/tests/3d/test_mesh.cc2
-rw-r--r--src/tests/assets/test_sequence.cc2
-rw-r--r--src/tests/common/effect_test_helpers.cc7
-rw-r--r--src/tests/common/offscreen_render_target.cc4
-rw-r--r--src/tests/gpu/test_demo_effects.cc63
-rw-r--r--src/tests/gpu/test_effect_base.cc32
-rw-r--r--src/tests/gpu/test_noise_functions.cc2
-rw-r--r--src/tests/gpu/test_sequence.cc25
-rw-r--r--src/tests/gpu/test_sequence_e2e.cc34
-rw-r--r--src/tests/gpu/test_shader_compilation.cc2
-rw-r--r--src/util/asset_manager.cc12
-rw-r--r--src/util/fatal_error.h16
63 files changed, 660 insertions, 701 deletions
diff --git a/src/3d/renderer_draw.cc b/src/3d/renderer_draw.cc
index 2b19787..f2d1323 100644
--- a/src/3d/renderer_draw.cc
+++ b/src/3d/renderer_draw.cc
@@ -61,7 +61,7 @@ void Renderer3D::update_uniforms(const Scene& scene, const Camera& camera,
if (obj.type == ObjectType::PLANE && obj.shared_user_data) {
// Safely cast shared_user_data to PlaneData* and get distance
plane_distance =
- static_cast<PlaneData*>(obj.shared_user_data.get())->distance;
+ ((PlaneData*)(obj.shared_user_data.get()))->distance;
}
data.params =
diff --git a/src/3d/renderer_pipelines.cc b/src/3d/renderer_pipelines.cc
index fed3983..57e71ae 100644
--- a/src/3d/renderer_pipelines.cc
+++ b/src/3d/renderer_pipelines.cc
@@ -17,7 +17,7 @@ void Renderer3D::create_pipeline() {
WGPURenderPipeline Renderer3D::create_pipeline_impl(bool use_bvh) {
// Main SDF shader
size_t size;
- const char* shader_code = reinterpret_cast<const char*>(
+ const char* shader_code = (const char*)(
GetAsset(AssetId::ASSET_SHADER_RENDERER_3D, &size));
// Compose the final shader by substituting the scene query implementation
@@ -134,7 +134,7 @@ WGPURenderPipeline Renderer3D::create_pipeline_impl(bool use_bvh) {
void Renderer3D::create_mesh_pipeline() {
size_t size;
- const char* shader_code = reinterpret_cast<const char*>(
+ const char* shader_code = (const char*)(
GetAsset(AssetId::ASSET_SHADER_MESH, &size));
ShaderComposer::CompositionMap composition_map;
@@ -261,7 +261,7 @@ void Renderer3D::create_mesh_pipeline() {
void Renderer3D::create_skybox_pipeline() {
size_t size;
- const char* shader_code = reinterpret_cast<const char*>(
+ const char* shader_code = (const char*)(
GetAsset(AssetId::ASSET_SHADER_SKYBOX, &size));
std::string composed_shader =
diff --git a/src/3d/scene_loader.cc b/src/3d/scene_loader.cc
index 286edca..1ff2cc2 100644
--- a/src/3d/scene_loader.cc
+++ b/src/3d/scene_loader.cc
@@ -9,7 +9,9 @@
#include <new> // For std::nothrow
#include <vector>
-bool SceneLoader::LoadScene(Scene& scene, const uint8_t* data, size_t size) {
+namespace SceneLoader {
+
+bool LoadScene(Scene& scene, const uint8_t* data, size_t size) {
if (!data || size < 16) { // Header size check
printf("SceneLoader: Data too small\n");
return false;
@@ -23,11 +25,11 @@ bool SceneLoader::LoadScene(Scene& scene, const uint8_t* data, size_t size) {
size_t offset = 4;
- uint32_t num_objects = *reinterpret_cast<const uint32_t*>(data + offset);
+ uint32_t num_objects = *(const uint32_t*)(data + offset);
offset += 4;
- uint32_t num_cameras = *reinterpret_cast<const uint32_t*>(data + offset);
+ uint32_t num_cameras = *(const uint32_t*)(data + offset);
offset += 4;
- uint32_t num_lights = *reinterpret_cast<const uint32_t*>(data + offset);
+ uint32_t num_lights = *(const uint32_t*)(data + offset);
offset += 4;
// printf("SceneLoader: Loading %d objects, %d cameras, %d lights\n",
@@ -43,48 +45,48 @@ bool SceneLoader::LoadScene(Scene& scene, const uint8_t* data, size_t size) {
if (offset + 4 > size)
return false;
- uint32_t type_val = *reinterpret_cast<const uint32_t*>(data + offset);
+ uint32_t type_val = *(const uint32_t*)(data + offset);
offset += 4;
ObjectType type = (ObjectType)type_val;
if (offset + 12 + 16 + 12 + 16 > size)
return false; // Transforms + Color
- float px = *reinterpret_cast<const float*>(data + offset);
+ float px = *(const float*)(data + offset);
offset += 4;
- float py = *reinterpret_cast<const float*>(data + offset);
+ float py = *(const float*)(data + offset);
offset += 4;
- float pz = *reinterpret_cast<const float*>(data + offset);
+ float pz = *(const float*)(data + offset);
offset += 4;
vec3 pos(px, py, pz);
- float rx = *reinterpret_cast<const float*>(data + offset);
+ float rx = *(const float*)(data + offset);
offset += 4;
- float ry = *reinterpret_cast<const float*>(data + offset);
+ float ry = *(const float*)(data + offset);
offset += 4;
- float rz = *reinterpret_cast<const float*>(data + offset);
+ float rz = *(const float*)(data + offset);
offset += 4;
- float rw = *reinterpret_cast<const float*>(data + offset);
+ float rw = *(const float*)(data + offset);
offset += 4;
quat rot(rx, ry, rz, rw);
- float sx = *reinterpret_cast<const float*>(data + offset);
+ float sx = *(const float*)(data + offset);
offset += 4;
- float sy = *reinterpret_cast<const float*>(data + offset);
+ float sy = *(const float*)(data + offset);
offset += 4;
- float sz = *reinterpret_cast<const float*>(data + offset);
+ float sz = *(const float*)(data + offset);
offset += 4;
vec3 scale(sx, sy, sz);
// Color components (cr, cg, cb, ca)
- float cr = *reinterpret_cast<const float*>(data + offset);
+ float cr = *(const float*)(data + offset);
offset += 4;
- float cg = *reinterpret_cast<const float*>(data + offset);
+ float cg = *(const float*)(data + offset);
offset += 4;
- float cb = *reinterpret_cast<const float*>(data + offset);
+ float cb = *(const float*)(data + offset);
offset += 4;
// Read ca, advance offset AFTER reading ca, then construct color
- float ca = *reinterpret_cast<const float*>(data + offset);
+ float ca = *(const float*)(data + offset);
offset += 4; // Offset is now after ca
vec4 color(cr, cg, cb, ca);
@@ -94,7 +96,7 @@ bool SceneLoader::LoadScene(Scene& scene, const uint8_t* data, size_t size) {
// Check bounds before reading plane_distance
if (offset + 4 > size)
return false;
- plane_distance = *reinterpret_cast<const float*>(data + offset);
+ plane_distance = *(const float*)(data + offset);
offset += 4; // Advance offset after reading plane_distance
}
@@ -103,7 +105,7 @@ bool SceneLoader::LoadScene(Scene& scene, const uint8_t* data, size_t size) {
// either after ca (if not PLANE) or after plane_distance (if PLANE).
if (offset + 4 > size)
return false;
- uint32_t name_len = *reinterpret_cast<const uint32_t*>(data + offset);
+ uint32_t name_len = *(const uint32_t*)(data + offset);
offset += 4;
AssetId mesh_id = (AssetId)0; // Default or INVALID (if 0 is invalid)
@@ -129,11 +131,11 @@ bool SceneLoader::LoadScene(Scene& scene, const uint8_t* data, size_t size) {
// Physics properties
if (offset + 4 + 4 + 4 > size)
return false;
- float mass = *reinterpret_cast<const float*>(data + offset);
+ float mass = *(const float*)(data + offset);
offset += 4;
- float restitution = *reinterpret_cast<const float*>(data + offset);
+ float restitution = *(const float*)(data + offset);
offset += 4;
- uint32_t is_static_u32 = *reinterpret_cast<const uint32_t*>(data + offset);
+ uint32_t is_static_u32 = *(const uint32_t*)(data + offset);
offset += 4;
bool is_static = (is_static_u32 != 0);
@@ -155,9 +157,9 @@ bool SceneLoader::LoadScene(Scene& scene, const uint8_t* data, size_t size) {
// Use std::make_shared for exception safety and efficiency
obj.shared_user_data = std::make_shared<PlaneData>();
// Assign the plane distance
- // Safely cast void* to PlaneData* using static_cast on the shared_ptr's
+ // Safely cast void* to PlaneData* using C-style cast on the shared_ptr's
// get()
- static_cast<PlaneData*>(obj.shared_user_data.get())->distance =
+ ((PlaneData*)(obj.shared_user_data.get()))->distance =
plane_distance;
}
@@ -166,4 +168,5 @@ bool SceneLoader::LoadScene(Scene& scene, const uint8_t* data, size_t size) {
}
return true;
-} \ No newline at end of file
+}
+} // namespace SceneLoader \ No newline at end of file
diff --git a/src/3d/scene_loader.h b/src/3d/scene_loader.h
index eabfb7a..c4fb9e9 100644
--- a/src/3d/scene_loader.h
+++ b/src/3d/scene_loader.h
@@ -4,12 +4,11 @@
#include <cstddef>
#include <cstdint>
-// SceneLoader handles parsing of binary scene files (.bin) exported from
-// Blender. It populates a Scene object with objects, lights, and cameras.
-class SceneLoader {
- public:
- // Loads a scene from a binary buffer.
- // Returns true on success, false on failure (e.g., invalid magic, version
- // mismatch).
- static bool LoadScene(Scene& scene, const uint8_t* data, size_t size);
-};
+namespace SceneLoader {
+
+// Loads a scene from a binary buffer.
+// Returns true on success, false on failure (e.g., invalid magic, version
+// mismatch).
+bool LoadScene(Scene& scene, const uint8_t* data, size_t size);
+
+} // namespace SceneLoader
diff --git a/src/app/main.cc b/src/app/main.cc
index eefec03..e020a2a 100644
--- a/src/app/main.cc
+++ b/src/app/main.cc
@@ -17,10 +17,10 @@
#include <csignal>
#endif
#endif
-#include "generated/assets.h" // Include generated asset header
+#include "generated/assets.h" // Include generated asset header
+#include "generated/timeline.h" // For GetDemoDuration(), RenderTimeline()
#include "gpu/demo_effects.h"
#include "gpu/gpu.h"
-#include "generated/timeline.h" // For GetDemoDuration(), RenderTimeline()
#include "platform/platform.h"
#include "util/math.h"
#include <cmath>
@@ -211,7 +211,8 @@ int main(int argc, char** argv) {
}
audio_start();
- g_last_audio_time = 0.0f; // Initialize to zero (will use smooth interpolation)
+ g_last_audio_time =
+ 0.0f; // Initialize to zero (will use smooth interpolation)
#if !defined(STRIP_ALL)
// Hot-reload setup
@@ -414,8 +415,8 @@ int main(int argc, char** argv) {
}
// Draw graphics using v2 timeline
- RenderTimeline(gpu_get_surface(), (float)current_physical_time, width, height,
- absolute_beat_time, visual_peak);
+ RenderTimeline(gpu_get_surface(), (float)current_physical_time, width,
+ height, absolute_beat_time, visual_peak);
last_frame_time = current_physical_time;
}
diff --git a/src/app/test_demo.cc b/src/app/test_demo.cc
index 6031aef..afeb3bd 100644
--- a/src/app/test_demo.cc
+++ b/src/app/test_demo.cc
@@ -309,7 +309,7 @@ int main(int argc, char** argv) {
// Draw graphics using v2 timeline
const float graphics_frame_time = (float)current_physical_time;
RenderTimeline(gpu_get_surface(), graphics_frame_time, width, height,
- absolute_beat_time, visual_peak);
+ absolute_beat_time, visual_peak);
}
// Shutdown
diff --git a/src/audio/audio.cc b/src/audio/audio.cc
index 9a6d689..89380cd 100644
--- a/src/audio/audio.cc
+++ b/src/audio/audio.cc
@@ -245,7 +245,8 @@ float audio_get_playback_time() {
const double elapsed = current_time - last_callback_time;
const float interpolated_samples =
(float)(elapsed * RING_BUFFER_SAMPLE_RATE * RING_BUFFER_CHANNELS);
- const float total_samples = (float)last_callback_samples + interpolated_samples;
+ const float total_samples =
+ (float)last_callback_samples + interpolated_samples;
return total_samples / (RING_BUFFER_SAMPLE_RATE * RING_BUFFER_CHANNELS);
}
}
diff --git a/src/audio/backend/miniaudio_backend.cc b/src/audio/backend/miniaudio_backend.cc
index ac473b4..312d36e 100644
--- a/src/audio/backend/miniaudio_backend.cc
+++ b/src/audio/backend/miniaudio_backend.cc
@@ -161,8 +161,8 @@ void MiniaudioBackend::audio_callback(ma_device* pDevice, void* pOutput,
}
#endif /* defined(DEBUG_LOG_RING_BUFFER) */
- // Peak calculation moved to audio_get_realtime_peak() for RMS-based measurement
- // (uses ring buffer peek for accurate time-windowed RMS)
+ // Peak calculation moved to audio_get_realtime_peak() for RMS-based
+ // measurement (uses ring buffer peek for accurate time-windowed RMS)
}
#if defined(DEBUG_LOG_AUDIO)
@@ -199,8 +199,8 @@ void MiniaudioBackend::init() {
// Solution 1: Force OS-level sample rate to 32kHz to avoid resampling
config.coreaudio.allowNominalSampleRateChange = MA_TRUE;
- // Solution 2: Use conservative performance profile for larger buffers
- config.performanceProfile = ma_performance_profile_conservative;
+ // Solution 2: Use low-latency performance profile for regular callbacks
+ config.performanceProfile = ma_performance_profile_low_latency;
// Let Core Audio choose the period size based on conservative profile
config.periodSizeInFrames = 0; // 0 = let backend decide
diff --git a/src/audio/backend/miniaudio_backend.h b/src/audio/backend/miniaudio_backend.h
index 435496c..953a0c0 100644
--- a/src/audio/backend/miniaudio_backend.h
+++ b/src/audio/backend/miniaudio_backend.h
@@ -34,7 +34,7 @@ class MiniaudioBackend : public AudioBackend {
static volatile float realtime_peak_;
// Smooth playback time interpolation (updated in callback)
- static volatile double last_callback_time_; // Absolute CLOCK_MONOTONIC time
+ static volatile double last_callback_time_; // Absolute CLOCK_MONOTONIC time
static volatile int64_t last_callback_samples_;
// Static callback required by miniaudio C API
diff --git a/src/audio/tracker.cc b/src/audio/tracker.cc
index e7da26a..9446c6f 100644
--- a/src/audio/tracker.cc
+++ b/src/audio/tracker.cc
@@ -149,7 +149,8 @@ void tracker_init() {
for (uint32_t pid = 0; pid < g_tracker_patterns_count; ++pid) {
const TrackerPattern& pattern = g_tracker_patterns[pid];
for (uint32_t i = 1; i < pattern.num_events; ++i) {
- FATAL_CHECK(pattern.events[i].unit_time >= pattern.events[i - 1].unit_time,
+ FATAL_CHECK(pattern.events[i].unit_time >=
+ pattern.events[i - 1].unit_time,
"Pattern %d has unsorted events: event[%d].time=%.3f < "
"event[%d].time=%.3f\n",
pid, i, pattern.events[i].unit_time, i - 1,
diff --git a/src/effects/flash_effect.cc b/src/effects/flash_effect.cc
index 1d0e629..7baf6a2 100644
--- a/src/effects/flash_effect.cc
+++ b/src/effects/flash_effect.cc
@@ -2,21 +2,21 @@
// Pulses white based on beat timing
#include "effects/flash_effect.h"
+#include "effects/shaders.h"
#include "gpu/post_process_helper.h"
-#include "gpu/shaders.h"
#include "util/fatal_error.h"
-FlashEffect::FlashEffect(const GpuContext& ctx,
- const std::vector<std::string>& inputs,
- const std::vector<std::string>& outputs)
- : Effect(ctx, inputs, outputs), pipeline_(nullptr), bind_group_(nullptr),
- sampler_(nullptr), dummy_texture_(nullptr), dummy_texture_view_(nullptr) {
+Flash::Flash(const GpuContext& ctx, const std::vector<std::string>& inputs,
+ const std::vector<std::string>& outputs, float start_time,
+ float end_time)
+ : Effect(ctx, inputs, outputs, start_time, end_time), pipeline_(nullptr),
+ bind_group_(nullptr), sampler_(nullptr), dummy_texture_(nullptr),
+ dummy_texture_view_(nullptr) {
HEADLESS_RETURN_IF_NULL(ctx_.device);
uniforms_buffer_.init(ctx_.device);
- pipeline_ = create_post_process_pipeline(ctx_.device,
- WGPUTextureFormat_RGBA8Unorm,
- flash_shader_wgsl);
+ pipeline_ = create_post_process_pipeline(
+ ctx_.device, WGPUTextureFormat_RGBA8Unorm, flash_shader_wgsl);
// Create dummy sampler (scene effects don't use texture input)
WGPUSamplerDescriptor sampler_desc = {};
@@ -39,17 +39,21 @@ FlashEffect::FlashEffect(const GpuContext& ctx,
dummy_texture_view_ = wgpuTextureCreateView(dummy_texture_, nullptr);
}
-FlashEffect::~FlashEffect() {
- if (bind_group_) wgpuBindGroupRelease(bind_group_);
- if (pipeline_) wgpuRenderPipelineRelease(pipeline_);
- if (sampler_) wgpuSamplerRelease(sampler_);
- if (dummy_texture_view_) wgpuTextureViewRelease(dummy_texture_view_);
- if (dummy_texture_) wgpuTextureRelease(dummy_texture_);
+Flash::~Flash() {
+ if (bind_group_)
+ wgpuBindGroupRelease(bind_group_);
+ if (pipeline_)
+ wgpuRenderPipelineRelease(pipeline_);
+ if (sampler_)
+ wgpuSamplerRelease(sampler_);
+ if (dummy_texture_view_)
+ wgpuTextureViewRelease(dummy_texture_view_);
+ if (dummy_texture_)
+ wgpuTextureRelease(dummy_texture_);
}
-void FlashEffect::render(WGPUCommandEncoder encoder,
- const UniformsSequenceParams& params,
- NodeRegistry& nodes) {
+void Flash::render(WGPUCommandEncoder encoder,
+ const UniformsSequenceParams& params, NodeRegistry& nodes) {
// Get output view (scene effects typically write to output, ignore input)
WGPUTextureView output_view = nodes.get_view(output_nodes_[0]);
@@ -57,22 +61,20 @@ void FlashEffect::render(WGPUCommandEncoder encoder,
uniforms_buffer_.update(ctx_.queue, params);
// Update bind group (use dummy texture for scene effect)
- pp_update_bind_group(ctx_.device, pipeline_, &bind_group_, dummy_texture_view_,
- uniforms_buffer_.get(), {nullptr, 0});
+ pp_update_bind_group(ctx_.device, pipeline_, &bind_group_,
+ dummy_texture_view_, uniforms_buffer_.get(),
+ {nullptr, 0});
// Render pass
WGPURenderPassColorAttachment color_attachment = {};
- color_attachment.view = output_view;
- color_attachment.depthSlice = WGPU_DEPTH_SLICE_UNDEFINED;
- color_attachment.loadOp = WGPULoadOp_Clear;
- color_attachment.storeOp = WGPUStoreOp_Store;
- color_attachment.clearValue = {0.0, 0.0, 0.0, 1.0};
+ gpu_init_color_attachment(color_attachment, output_view);
WGPURenderPassDescriptor pass_desc = {};
pass_desc.colorAttachmentCount = 1;
pass_desc.colorAttachments = &color_attachment;
- WGPURenderPassEncoder pass = wgpuCommandEncoderBeginRenderPass(encoder, &pass_desc);
+ WGPURenderPassEncoder pass =
+ wgpuCommandEncoderBeginRenderPass(encoder, &pass_desc);
wgpuRenderPassEncoderSetPipeline(pass, pipeline_);
wgpuRenderPassEncoderSetBindGroup(pass, 0, bind_group_, 0, nullptr);
wgpuRenderPassEncoderDraw(pass, 3, 1, 0, 0);
diff --git a/src/effects/flash_effect.h b/src/effects/flash_effect.h
index b9bbff8..1117e0a 100644
--- a/src/effects/flash_effect.h
+++ b/src/effects/flash_effect.h
@@ -5,15 +5,14 @@
#include "gpu/effect.h"
#include "gpu/uniform_helper.h"
-class FlashEffect : public Effect {
+class Flash : public Effect {
public:
- FlashEffect(const GpuContext& ctx,
- const std::vector<std::string>& inputs,
- const std::vector<std::string>& outputs);
- ~FlashEffect() override;
+ Flash(const GpuContext& ctx, const std::vector<std::string>& inputs,
+ const std::vector<std::string>& outputs, float start_time,
+ float end_time);
+ ~Flash() override;
- void render(WGPUCommandEncoder encoder,
- const UniformsSequenceParams& params,
+ void render(WGPUCommandEncoder encoder, const UniformsSequenceParams& params,
NodeRegistry& nodes) override;
private:
diff --git a/src/effects/gaussian_blur_effect.cc b/src/effects/gaussian_blur_effect.cc
index adb094c..7304321 100644
--- a/src/effects/gaussian_blur_effect.cc
+++ b/src/effects/gaussian_blur_effect.cc
@@ -1,21 +1,22 @@
-// Gaussian blur effect v2 implementation
+// Gaussian blur effect implementation
#include "effects/gaussian_blur_effect.h"
-#include "util/fatal_error.h"
+#include "effects/shaders.h"
#include "gpu/post_process_helper.h"
-#include "gpu/shaders.h"
+#include "util/fatal_error.h"
-GaussianBlurEffect::GaussianBlurEffect(const GpuContext& ctx,
- const std::vector<std::string>& inputs,
- const std::vector<std::string>& outputs)
- : Effect(ctx, inputs, outputs), pipeline_(nullptr), bind_group_(nullptr),
+GaussianBlur::GaussianBlur(const GpuContext& ctx,
+ const std::vector<std::string>& inputs,
+ const std::vector<std::string>& outputs, float start_time,
+ float end_time)
+ : Effect(ctx, inputs, outputs, start_time, end_time), pipeline_(nullptr), bind_group_(nullptr),
sampler_(nullptr) {
// Headless mode: skip GPU resource creation (compiled out in STRIP_ALL)
HEADLESS_RETURN_IF_NULL(ctx_.device);
// Create pipeline
- pipeline_ = create_post_process_pipeline(ctx_.device, WGPUTextureFormat_RGBA8Unorm,
- gaussian_blur_v2_shader_wgsl);
+ pipeline_ = create_post_process_pipeline(
+ ctx_.device, WGPUTextureFormat_RGBA8Unorm, gaussian_blur_shader_wgsl);
// Create sampler
WGPUSamplerDescriptor sampler_desc = {};
@@ -31,9 +32,9 @@ GaussianBlurEffect::GaussianBlurEffect(const GpuContext& ctx,
uniforms_buffer_.init(ctx_.device);
}
-void GaussianBlurEffect::render(WGPUCommandEncoder encoder,
- const UniformsSequenceParams& params,
- NodeRegistry& nodes) {
+void GaussianBlur::render(WGPUCommandEncoder encoder,
+ const UniformsSequenceParams& params,
+ NodeRegistry& nodes) {
// Get input/output views
WGPUTextureView input_view = nodes.get_view(input_nodes_[0]);
WGPUTextureView output_view = nodes.get_view(output_nodes_[0]);
@@ -67,17 +68,14 @@ void GaussianBlurEffect::render(WGPUCommandEncoder encoder,
// Render pass
WGPURenderPassColorAttachment color_attachment = {};
- color_attachment.view = output_view;
- color_attachment.depthSlice = WGPU_DEPTH_SLICE_UNDEFINED;
- color_attachment.loadOp = WGPULoadOp_Clear;
- color_attachment.storeOp = WGPUStoreOp_Store;
- color_attachment.clearValue = {0.0, 0.0, 0.0, 1.0};
+ gpu_init_color_attachment(color_attachment, output_view);
WGPURenderPassDescriptor pass_desc = {};
pass_desc.colorAttachmentCount = 1;
pass_desc.colorAttachments = &color_attachment;
- WGPURenderPassEncoder pass = wgpuCommandEncoderBeginRenderPass(encoder, &pass_desc);
+ WGPURenderPassEncoder pass =
+ wgpuCommandEncoderBeginRenderPass(encoder, &pass_desc);
wgpuRenderPassEncoderSetPipeline(pass, pipeline_);
wgpuRenderPassEncoderSetBindGroup(pass, 0, bind_group_, 0, nullptr);
wgpuRenderPassEncoderDraw(pass, 3, 1, 0, 0);
diff --git a/src/effects/gaussian_blur_effect.h b/src/effects/gaussian_blur_effect.h
index 8bf34dc..cc9ff56 100644
--- a/src/effects/gaussian_blur_effect.h
+++ b/src/effects/gaussian_blur_effect.h
@@ -6,7 +6,7 @@
#include "gpu/uniform_helper.h"
struct GaussianBlurParams {
- float strength = 1.0f;
+ float strength = 8.0f;
float strength_audio = 0.5f;
float stretch = 1.0f;
float _pad = 0.0f;
@@ -14,11 +14,11 @@ struct GaussianBlurParams {
static_assert(sizeof(GaussianBlurParams) == 16,
"GaussianBlurParams must be 16 bytes");
-class GaussianBlurEffect : public Effect {
+class GaussianBlur : public Effect {
public:
- GaussianBlurEffect(const GpuContext& ctx,
- const std::vector<std::string>& inputs,
- const std::vector<std::string>& outputs);
+ GaussianBlur(const GpuContext& ctx, const std::vector<std::string>& inputs,
+ const std::vector<std::string>& outputs, float start_time,
+ float end_time);
void render(WGPUCommandEncoder encoder, const UniformsSequenceParams& params,
NodeRegistry& nodes) override;
@@ -31,4 +31,3 @@ class GaussianBlurEffect : public Effect {
UniformBuffer<GaussianBlurParams> params_buffer_;
UniformBuffer<UniformsSequenceParams> uniforms_buffer_;
};
-
diff --git a/src/effects/heptagon_effect.cc b/src/effects/heptagon_effect.cc
index 303ab2a..c472f2f 100644
--- a/src/effects/heptagon_effect.cc
+++ b/src/effects/heptagon_effect.cc
@@ -1,24 +1,26 @@
-// Heptagon effect v2 implementation
+// Heptagon effect implementation
#include "effects/heptagon_effect.h"
-#include "util/fatal_error.h"
+#include "effects/shaders.h"
#include "gpu/gpu.h"
#include "gpu/post_process_helper.h"
-#include "gpu/shaders.h"
+#include "util/fatal_error.h"
-HeptagonEffect::HeptagonEffect(const GpuContext& ctx,
- const std::vector<std::string>& inputs,
- const std::vector<std::string>& outputs)
- : Effect(ctx, inputs, outputs), pipeline_(nullptr), bind_group_(nullptr), sampler_(nullptr) {
+Heptagon::Heptagon(const GpuContext& ctx,
+ const std::vector<std::string>& inputs,
+ const std::vector<std::string>& outputs, float start_time,
+ float end_time)
+ : Effect(ctx, inputs, outputs, start_time, end_time), pipeline_(nullptr), bind_group_(nullptr),
+ sampler_(nullptr) {
// Headless mode: skip GPU resource creation (compiled out in STRIP_ALL)
HEADLESS_RETURN_IF_NULL(ctx_.device);
// Init uniforms
uniforms_buffer_.init(ctx_.device);
- // Create pipeline (standard v2 post-process, no depth)
- pipeline_ = create_post_process_pipeline(ctx_.device, WGPUTextureFormat_RGBA8Unorm,
- heptagon_v2_shader_wgsl);
+ // Create pipeline (standard post-process, no depth)
+ pipeline_ = create_post_process_pipeline(
+ ctx_.device, WGPUTextureFormat_RGBA8Unorm, heptagon_shader_wgsl);
// Create dummy sampler (scene effects don't use texture input)
WGPUSamplerDescriptor sampler_desc = {};
@@ -41,17 +43,22 @@ HeptagonEffect::HeptagonEffect(const GpuContext& ctx,
dummy_texture_view_ = wgpuTextureCreateView(dummy_texture_, nullptr);
}
-HeptagonEffect::~HeptagonEffect() {
- if (bind_group_) wgpuBindGroupRelease(bind_group_);
- if (pipeline_) wgpuRenderPipelineRelease(pipeline_);
- if (sampler_) wgpuSamplerRelease(sampler_);
- if (dummy_texture_view_) wgpuTextureViewRelease(dummy_texture_view_);
- if (dummy_texture_) wgpuTextureRelease(dummy_texture_);
+Heptagon::~Heptagon() {
+ if (bind_group_)
+ wgpuBindGroupRelease(bind_group_);
+ if (pipeline_)
+ wgpuRenderPipelineRelease(pipeline_);
+ if (sampler_)
+ wgpuSamplerRelease(sampler_);
+ if (dummy_texture_view_)
+ wgpuTextureViewRelease(dummy_texture_view_);
+ if (dummy_texture_)
+ wgpuTextureRelease(dummy_texture_);
}
-void HeptagonEffect::render(WGPUCommandEncoder encoder,
- const UniformsSequenceParams& params,
- NodeRegistry& nodes) {
+void Heptagon::render(WGPUCommandEncoder encoder,
+ const UniformsSequenceParams& params,
+ NodeRegistry& nodes) {
// Get output view (scene effects typically write to output, ignore input)
WGPUTextureView output_view = nodes.get_view(output_nodes_[0]);
@@ -59,25 +66,23 @@ void HeptagonEffect::render(WGPUCommandEncoder encoder,
uniforms_buffer_.update(ctx_.queue, params);
// Create bind group (use dummy texture for scene effect)
- pp_update_bind_group(ctx_.device, pipeline_, &bind_group_, dummy_texture_view_,
- uniforms_buffer_.get(), {nullptr, 0});
+ pp_update_bind_group(ctx_.device, pipeline_, &bind_group_,
+ dummy_texture_view_, uniforms_buffer_.get(),
+ {nullptr, 0});
// Render pass
WGPURenderPassColorAttachment color_attachment = {};
- color_attachment.view = output_view;
- color_attachment.depthSlice = WGPU_DEPTH_SLICE_UNDEFINED;
- color_attachment.loadOp = WGPULoadOp_Clear;
- color_attachment.storeOp = WGPUStoreOp_Store;
- color_attachment.clearValue = {0.0, 0.0, 0.0, 1.0};
+ gpu_init_color_attachment(color_attachment, output_view);
WGPURenderPassDescriptor pass_desc = {};
pass_desc.colorAttachmentCount = 1;
pass_desc.colorAttachments = &color_attachment;
- WGPURenderPassEncoder pass = wgpuCommandEncoderBeginRenderPass(encoder, &pass_desc);
+ WGPURenderPassEncoder pass =
+ wgpuCommandEncoderBeginRenderPass(encoder, &pass_desc);
wgpuRenderPassEncoderSetPipeline(pass, pipeline_);
wgpuRenderPassEncoderSetBindGroup(pass, 0, bind_group_, 0, nullptr);
- wgpuRenderPassEncoderDraw(pass, 21, 1, 0, 0); // 7 triangles * 3 vertices
+ wgpuRenderPassEncoderDraw(pass, 3, 1, 0, 0); // Fullscreen triangle
wgpuRenderPassEncoderEnd(pass);
wgpuRenderPassEncoderRelease(pass);
}
diff --git a/src/effects/heptagon_effect.h b/src/effects/heptagon_effect.h
index 9f148a1..ef05d79 100644
--- a/src/effects/heptagon_effect.h
+++ b/src/effects/heptagon_effect.h
@@ -5,11 +5,12 @@
#include "gpu/effect.h"
#include "gpu/uniform_helper.h"
-class HeptagonEffect : public Effect {
+class Heptagon : public Effect {
public:
- HeptagonEffect(const GpuContext& ctx, const std::vector<std::string>& inputs,
- const std::vector<std::string>& outputs);
- ~HeptagonEffect();
+ Heptagon(const GpuContext& ctx, const std::vector<std::string>& inputs,
+ const std::vector<std::string>& outputs, float start_time,
+ float end_time);
+ ~Heptagon();
void render(WGPUCommandEncoder encoder, const UniformsSequenceParams& params,
NodeRegistry& nodes) override;
@@ -22,4 +23,3 @@ class HeptagonEffect : public Effect {
WGPUTextureView dummy_texture_view_;
UniformBuffer<UniformsSequenceParams> uniforms_buffer_;
};
-
diff --git a/src/effects/hybrid3_d_effect.cc b/src/effects/hybrid3_d_effect.cc
index 0e6ea35..5832b57 100644
--- a/src/effects/hybrid3_d_effect.cc
+++ b/src/effects/hybrid3_d_effect.cc
@@ -1,15 +1,17 @@
// This file is part of the 64k demo project.
-// It implements Hybrid3DEffect (simplified v2 port).
+// It implements Hybrid3D (simplified v2 port).
// TODO: Full Renderer3D integration with texture manager, noise assets
#include "util/fatal_error.h"
#include "effects/hybrid3_d_effect.h"
+#include "gpu/gpu.h"
#include <cmath>
-Hybrid3DEffect::Hybrid3DEffect(const GpuContext& ctx,
- const std::vector<std::string>& inputs,
- const std::vector<std::string>& outputs)
- : Effect(ctx, inputs, outputs), depth_node_(outputs[0] + "_depth"),
+Hybrid3D::Hybrid3D(const GpuContext& ctx,
+ const std::vector<std::string>& inputs,
+ const std::vector<std::string>& outputs, float start_time,
+ float end_time)
+ : Effect(ctx, inputs, outputs, start_time, end_time), depth_node_(outputs[0] + "_depth"),
dummy_texture_(nullptr), dummy_texture_view_(nullptr) {
// Headless mode: skip GPU resource creation (compiled out in STRIP_ALL)
HEADLESS_RETURN_IF_NULL(ctx_.device);
@@ -32,24 +34,12 @@ Hybrid3DEffect::Hybrid3DEffect(const GpuContext& ctx,
uint32_t white_pixel = 0xFFFFFFFF;
#if defined(DEMO_CROSS_COMPILE_WIN32)
WGPUImageCopyTexture dst = {
- .texture = dummy_texture_,
- .mipLevel = 0,
- .origin = {0, 0, 0}
- };
- WGPUTextureDataLayout data_layout = {
- .bytesPerRow = 4,
- .rowsPerImage = 1
- };
+ .texture = dummy_texture_, .mipLevel = 0, .origin = {0, 0, 0}};
+ WGPUTextureDataLayout data_layout = {.bytesPerRow = 4, .rowsPerImage = 1};
#else
WGPUTexelCopyTextureInfo dst = {
- .texture = dummy_texture_,
- .mipLevel = 0,
- .origin = {0, 0, 0}
- };
- WGPUTexelCopyBufferLayout data_layout = {
- .bytesPerRow = 4,
- .rowsPerImage = 1
- };
+ .texture = dummy_texture_, .mipLevel = 0, .origin = {0, 0, 0}};
+ WGPUTexelCopyBufferLayout data_layout = {.bytesPerRow = 4, .rowsPerImage = 1};
#endif
WGPUExtent3D size = {1, 1, 1};
wgpuQueueWriteTexture(ctx_.queue, &dst, &white_pixel, 4, &data_layout, &size);
@@ -67,8 +57,9 @@ Hybrid3DEffect::Hybrid3DEffect(const GpuContext& ctx,
scene_.add_object(center);
for (int i = 0; i < 8; ++i) {
- ObjectType type = (i % 3 == 1) ? ObjectType::TORUS :
- (i % 3 == 2) ? ObjectType::BOX : ObjectType::SPHERE;
+ ObjectType type = (i % 3 == 1) ? ObjectType::TORUS
+ : (i % 3 == 2) ? ObjectType::BOX
+ : ObjectType::SPHERE;
Object3D obj(type);
float angle = (i / 8.0f) * 6.28318f;
@@ -86,7 +77,7 @@ Hybrid3DEffect::Hybrid3DEffect(const GpuContext& ctx,
}
}
-Hybrid3DEffect::~Hybrid3DEffect() {
+Hybrid3D::~Hybrid3D() {
if (dummy_texture_view_)
wgpuTextureViewRelease(dummy_texture_view_);
if (dummy_texture_)
@@ -94,14 +85,14 @@ Hybrid3DEffect::~Hybrid3DEffect() {
renderer_.shutdown();
}
-void Hybrid3DEffect::declare_nodes(NodeRegistry& registry) {
+void Hybrid3D::declare_nodes(NodeRegistry& registry) {
// Declare depth buffer node
registry.declare_node(depth_node_, NodeType::DEPTH24, -1, -1);
}
-void Hybrid3DEffect::render(WGPUCommandEncoder encoder,
- const UniformsSequenceParams& params,
- NodeRegistry& nodes) {
+void Hybrid3D::render(WGPUCommandEncoder encoder,
+ const UniformsSequenceParams& params,
+ NodeRegistry& nodes) {
// Update camera (orbiting)
float angle = params.time * 0.3f;
vec3 cam_pos = vec3(std::cos(angle) * 10.0f, 5.0f, std::sin(angle) * 10.0f);
@@ -113,6 +104,25 @@ void Hybrid3DEffect::render(WGPUCommandEncoder encoder,
WGPUTextureView color_view = nodes.get_view(output_nodes_[0]);
WGPUTextureView depth_view = nodes.get_view(depth_node_);
- // Render 3D scene
- renderer_.render(scene_, camera_, params.time, color_view, depth_view);
+ // Render 3D scene using sequence encoder
+ WGPURenderPassColorAttachment color_attachment = {};
+ gpu_init_color_attachment(color_attachment, color_view);
+ color_attachment.clearValue = {0.05f, 0.05f, 0.05f, 1.0f};
+
+ WGPURenderPassDepthStencilAttachment depth_attachment = {};
+ depth_attachment.view = depth_view;
+ depth_attachment.depthLoadOp = WGPULoadOp_Clear;
+ depth_attachment.depthStoreOp = WGPUStoreOp_Store;
+ depth_attachment.depthClearValue = 1.0f;
+
+ WGPURenderPassDescriptor pass_desc = {};
+ pass_desc.colorAttachmentCount = 1;
+ pass_desc.colorAttachments = &color_attachment;
+ pass_desc.depthStencilAttachment = &depth_attachment;
+
+ WGPURenderPassEncoder pass =
+ wgpuCommandEncoderBeginRenderPass(encoder, &pass_desc);
+ renderer_.draw(pass, scene_, camera_, params.time);
+ wgpuRenderPassEncoderEnd(pass);
+ wgpuRenderPassEncoderRelease(pass);
}
diff --git a/src/effects/hybrid3_d_effect.h b/src/effects/hybrid3_d_effect.h
index e6e0f49..e0aa6da 100644
--- a/src/effects/hybrid3_d_effect.h
+++ b/src/effects/hybrid3_d_effect.h
@@ -9,16 +9,15 @@
#include "3d/scene.h"
#include "gpu/effect.h"
-class Hybrid3DEffect : public Effect {
+class Hybrid3D : public Effect {
public:
- Hybrid3DEffect(const GpuContext& ctx,
- const std::vector<std::string>& inputs,
- const std::vector<std::string>& outputs);
- ~Hybrid3DEffect() override;
+ Hybrid3D(const GpuContext& ctx, const std::vector<std::string>& inputs,
+ const std::vector<std::string>& outputs, float start_time,
+ float end_time);
+ ~Hybrid3D() override;
void declare_nodes(NodeRegistry& registry) override;
- void render(WGPUCommandEncoder encoder,
- const UniformsSequenceParams& params,
+ void render(WGPUCommandEncoder encoder, const UniformsSequenceParams& params,
NodeRegistry& nodes) override;
private:
diff --git a/src/effects/particles_effect.cc b/src/effects/particles_effect.cc
index b9e2b9c..d83f303 100644
--- a/src/effects/particles_effect.cc
+++ b/src/effects/particles_effect.cc
@@ -1,16 +1,17 @@
// This file is part of the 64k demo project.
-// It implements the ParticlesEffect.
+// It implements the Particles.
-#include "util/fatal_error.h"
#include "effects/particles_effect.h"
+#include "effects/shaders.h"
#include "gpu/gpu.h"
-#include "gpu/shaders.h"
+#include "util/fatal_error.h"
#include <vector>
-ParticlesEffect::ParticlesEffect(const GpuContext& ctx,
- const std::vector<std::string>& inputs,
- const std::vector<std::string>& outputs)
- : Effect(ctx, inputs, outputs) {
+Particles::Particles(const GpuContext& ctx,
+ const std::vector<std::string>& inputs,
+ const std::vector<std::string>& outputs, float start_time,
+ float end_time)
+ : Effect(ctx, inputs, outputs, start_time, end_time) {
// Headless mode: skip GPU resource creation (compiled out in STRIP_ALL)
HEADLESS_RETURN_IF_NULL(ctx_.device);
@@ -49,7 +50,7 @@ ParticlesEffect::ParticlesEffect(const GpuContext& ctx,
ResourceBinding compute_bindings[] = {
{particles_buffer_, WGPUBufferBindingType_Storage},
{uniforms_.get(), WGPUBufferBindingType_Uniform}};
- compute_pass_ = gpu_create_compute_pass(ctx_.device, particle_compute_v2_wgsl,
+ compute_pass_ = gpu_create_compute_pass(ctx_.device, particle_compute_wgsl,
compute_bindings, 2);
compute_pass_.workgroup_size_x = (NUM_PARTICLES + 63) / 64;
@@ -57,42 +58,44 @@ ParticlesEffect::ParticlesEffect(const GpuContext& ctx,
ResourceBinding render_bindings[] = {
{particles_buffer_, WGPUBufferBindingType_ReadOnlyStorage},
{uniforms_.get(), WGPUBufferBindingType_Uniform}};
- render_pass_ = gpu_create_render_pass(ctx_.device, WGPUTextureFormat_RGBA8Unorm,
- particle_render_v2_wgsl, render_bindings, 2);
+ render_pass_ =
+ gpu_create_render_pass(ctx_.device, WGPUTextureFormat_RGBA8Unorm,
+ particle_render_wgsl, render_bindings, 2);
render_pass_.vertex_count = 6;
render_pass_.instance_count = NUM_PARTICLES;
}
-void ParticlesEffect::render(WGPUCommandEncoder encoder,
- const UniformsSequenceParams& params,
- NodeRegistry& nodes) {
+void Particles::render(WGPUCommandEncoder encoder,
+ const UniformsSequenceParams& params,
+ NodeRegistry& nodes) {
// Update uniforms
uniforms_.update(ctx_.queue, params);
// Run compute pass (particle simulation)
- WGPUComputePassEncoder compute = wgpuCommandEncoderBeginComputePass(encoder, nullptr);
+ WGPUComputePassEncoder compute =
+ wgpuCommandEncoderBeginComputePass(encoder, nullptr);
wgpuComputePassEncoderSetPipeline(compute, compute_pass_.pipeline);
- wgpuComputePassEncoderSetBindGroup(compute, 0, compute_pass_.bind_group, 0, nullptr);
- wgpuComputePassEncoderDispatchWorkgroups(compute, compute_pass_.workgroup_size_x, 1, 1);
+ wgpuComputePassEncoderSetBindGroup(compute, 0, compute_pass_.bind_group, 0,
+ nullptr);
+ wgpuComputePassEncoderDispatchWorkgroups(
+ compute, compute_pass_.workgroup_size_x, 1, 1);
wgpuComputePassEncoderEnd(compute);
// Run render pass (draw particles to output)
WGPUTextureView output_view = nodes.get_view(output_nodes_[0]);
- WGPURenderPassColorAttachment color_attachment = {
- .view = output_view,
- .depthSlice = WGPU_DEPTH_SLICE_UNDEFINED,
- .loadOp = WGPULoadOp_Clear,
- .storeOp = WGPUStoreOp_Store,
- .clearValue = {0.0, 0.0, 0.0, 1.0}};
+ WGPURenderPassColorAttachment color_attachment = {};
+ gpu_init_color_attachment(color_attachment, output_view);
WGPURenderPassDescriptor render_desc = {
- .colorAttachmentCount = 1,
- .colorAttachments = &color_attachment};
+ .colorAttachmentCount = 1, .colorAttachments = &color_attachment};
- WGPURenderPassEncoder pass = wgpuCommandEncoderBeginRenderPass(encoder, &render_desc);
+ WGPURenderPassEncoder pass =
+ wgpuCommandEncoderBeginRenderPass(encoder, &render_desc);
wgpuRenderPassEncoderSetPipeline(pass, render_pass_.pipeline);
- wgpuRenderPassEncoderSetBindGroup(pass, 0, render_pass_.bind_group, 0, nullptr);
- wgpuRenderPassEncoderDraw(pass, render_pass_.vertex_count, render_pass_.instance_count, 0, 0);
+ wgpuRenderPassEncoderSetBindGroup(pass, 0, render_pass_.bind_group, 0,
+ nullptr);
+ wgpuRenderPassEncoderDraw(pass, render_pass_.vertex_count,
+ render_pass_.instance_count, 0, 0);
wgpuRenderPassEncoderEnd(pass);
}
diff --git a/src/effects/particles_effect.h b/src/effects/particles_effect.h
index 76c2ef4..38c60d7 100644
--- a/src/effects/particles_effect.h
+++ b/src/effects/particles_effect.h
@@ -18,13 +18,12 @@ struct Particle {
float color[4];
};
-class ParticlesEffect : public Effect {
+class Particles : public Effect {
public:
- ParticlesEffect(const GpuContext& ctx,
- const std::vector<std::string>& inputs,
- const std::vector<std::string>& outputs);
- void render(WGPUCommandEncoder encoder,
- const UniformsSequenceParams& params,
+ Particles(const GpuContext& ctx, const std::vector<std::string>& inputs,
+ const std::vector<std::string>& outputs, float start_time,
+ float end_time);
+ void render(WGPUCommandEncoder encoder, const UniformsSequenceParams& params,
NodeRegistry& nodes) override;
private:
@@ -33,4 +32,3 @@ class ParticlesEffect : public Effect {
GpuBuffer particles_buffer_;
UniformBuffer<UniformsSequenceParams> uniforms_;
};
-
diff --git a/src/effects/passthrough_effect.cc b/src/effects/passthrough_effect.cc
index 56e3711..b9d9337 100644
--- a/src/effects/passthrough_effect.cc
+++ b/src/effects/passthrough_effect.cc
@@ -1,23 +1,24 @@
-// Passthrough effect v2 implementation
+// Passthrough effect implementation
#include "effects/passthrough_effect.h"
-#include "util/fatal_error.h"
+#include "effects/shaders.h"
#include "gpu/post_process_helper.h"
-#include "gpu/shaders.h"
+#include "util/fatal_error.h"
-PassthroughEffect::PassthroughEffect(const GpuContext& ctx,
- const std::vector<std::string>& inputs,
- const std::vector<std::string>& outputs)
- : Effect(ctx, inputs, outputs), pipeline_(nullptr), bind_group_(nullptr),
- sampler_(nullptr) {
+Passthrough::Passthrough(const GpuContext& ctx,
+ const std::vector<std::string>& inputs,
+ const std::vector<std::string>& outputs,
+ float start_time, float end_time)
+ : Effect(ctx, inputs, outputs, start_time, end_time), pipeline_(nullptr),
+ bind_group_(nullptr), sampler_(nullptr) {
// Headless mode: skip GPU resource creation (compiled out in STRIP_ALL)
HEADLESS_RETURN_IF_NULL(ctx_.device);
// Init uniform buffer
uniforms_buffer_.init(ctx_.device);
// Create pipeline (simple version without effect params)
- pipeline_ = create_post_process_pipeline_simple(ctx_.device, WGPUTextureFormat_RGBA8Unorm,
- passthrough_v2_shader_wgsl);
+ pipeline_ = create_post_process_pipeline_simple(
+ ctx_.device, WGPUTextureFormat_RGBA8Unorm, passthrough_shader_wgsl);
// Create sampler
WGPUSamplerDescriptor sampler_desc = {};
@@ -31,9 +32,9 @@ PassthroughEffect::PassthroughEffect(const GpuContext& ctx,
sampler_ = wgpuDeviceCreateSampler(ctx_.device, &sampler_desc);
}
-void PassthroughEffect::render(WGPUCommandEncoder encoder,
- const UniformsSequenceParams& params,
- NodeRegistry& nodes) {
+void Passthrough::render(WGPUCommandEncoder encoder,
+ const UniformsSequenceParams& params,
+ NodeRegistry& nodes) {
// Get input/output views
WGPUTextureView input_view = nodes.get_view(input_nodes_[0]);
WGPUTextureView output_view = nodes.get_view(output_nodes_[0]);
@@ -62,22 +63,18 @@ void PassthroughEffect::render(WGPUCommandEncoder encoder,
bind_group_ = wgpuDeviceCreateBindGroup(ctx_.device, &bg_desc);
// Render pass
- WGPURenderPassColorAttachment color_attachment = {
- .view = output_view,
- .depthSlice = WGPU_DEPTH_SLICE_UNDEFINED,
- .loadOp = WGPULoadOp_Clear,
- .storeOp = WGPUStoreOp_Store,
- .clearValue = {0.0, 0.0, 0.0, 1.0}
- };
+ WGPURenderPassColorAttachment color_attachment = {};
+ gpu_init_color_attachment(color_attachment, output_view);
WGPURenderPassDescriptor pass_desc = {};
pass_desc.colorAttachmentCount = 1;
pass_desc.colorAttachments = &color_attachment;
- WGPURenderPassEncoder pass = wgpuCommandEncoderBeginRenderPass(encoder, &pass_desc);
+ WGPURenderPassEncoder pass =
+ wgpuCommandEncoderBeginRenderPass(encoder, &pass_desc);
wgpuRenderPassEncoderSetPipeline(pass, pipeline_);
wgpuRenderPassEncoderSetBindGroup(pass, 0, bind_group_, 0, nullptr);
- wgpuRenderPassEncoderDraw(pass, 3, 1, 0, 0); // Fullscreen triangle
+ wgpuRenderPassEncoderDraw(pass, 3, 1, 0, 0); // Fullscreen triangle
wgpuRenderPassEncoderEnd(pass);
wgpuRenderPassEncoderRelease(pass);
}
diff --git a/src/effects/passthrough_effect.h b/src/effects/passthrough_effect.h
index 125ac5a..f684b9b 100644
--- a/src/effects/passthrough_effect.h
+++ b/src/effects/passthrough_effect.h
@@ -5,10 +5,11 @@
#include "gpu/effect.h"
#include "gpu/uniform_helper.h"
-class PassthroughEffect : public Effect {
+class Passthrough : public Effect {
public:
- PassthroughEffect(const GpuContext& ctx, const std::vector<std::string>& inputs,
- const std::vector<std::string>& outputs);
+ Passthrough(const GpuContext& ctx, const std::vector<std::string>& inputs,
+ const std::vector<std::string>& outputs, float start_time,
+ float end_time);
void render(WGPUCommandEncoder encoder, const UniformsSequenceParams& params,
NodeRegistry& nodes) override;
diff --git a/src/effects/peak_meter_effect.cc b/src/effects/peak_meter_effect.cc
index 692d851..d823e20 100644
--- a/src/effects/peak_meter_effect.cc
+++ b/src/effects/peak_meter_effect.cc
@@ -5,10 +5,11 @@
#include "gpu/shader_composer.h"
#include "util/fatal_error.h"
-PeakMeterEffect::PeakMeterEffect(const GpuContext& ctx,
- const std::vector<std::string>& inputs,
- const std::vector<std::string>& outputs)
- : Effect(ctx, inputs, outputs), pipeline_(nullptr), bind_group_(nullptr) {
+PeakMeter::PeakMeter(const GpuContext& ctx,
+ const std::vector<std::string>& inputs,
+ const std::vector<std::string>& outputs, float start_time,
+ float end_time)
+ : Effect(ctx, inputs, outputs, start_time, end_time), pipeline_(nullptr), bind_group_(nullptr) {
HEADLESS_RETURN_IF_NULL(ctx_.device);
uniforms_buffer_.init(ctx_.device);
@@ -58,19 +59,20 @@ PeakMeterEffect::PeakMeterEffect(const GpuContext& ctx,
std::string shader_code =
ShaderComposer::Get().Compose({"common_uniforms"}, shader_main);
- pipeline_ = create_post_process_pipeline(ctx_.device,
- WGPUTextureFormat_RGBA8Unorm,
- shader_code.c_str());
+ pipeline_ = create_post_process_pipeline(
+ ctx_.device, WGPUTextureFormat_RGBA8Unorm, shader_code.c_str());
}
-PeakMeterEffect::~PeakMeterEffect() {
- if (bind_group_) wgpuBindGroupRelease(bind_group_);
- if (pipeline_) wgpuRenderPipelineRelease(pipeline_);
+PeakMeter::~PeakMeter() {
+ if (bind_group_)
+ wgpuBindGroupRelease(bind_group_);
+ if (pipeline_)
+ wgpuRenderPipelineRelease(pipeline_);
}
-void PeakMeterEffect::render(WGPUCommandEncoder encoder,
- const UniformsSequenceParams& params,
- NodeRegistry& nodes) {
+void PeakMeter::render(WGPUCommandEncoder encoder,
+ const UniformsSequenceParams& params,
+ NodeRegistry& nodes) {
WGPUTextureView input_view = nodes.get_view(input_nodes_[0]);
WGPUTextureView output_view = nodes.get_view(output_nodes_[0]);
@@ -79,17 +81,15 @@ void PeakMeterEffect::render(WGPUCommandEncoder encoder,
uniforms_buffer_.get(), {nullptr, 0});
WGPURenderPassColorAttachment color_attachment = {};
- color_attachment.view = output_view;
- color_attachment.depthSlice = WGPU_DEPTH_SLICE_UNDEFINED;
+ gpu_init_color_attachment(color_attachment, output_view);
color_attachment.loadOp = WGPULoadOp_Load;
- color_attachment.storeOp = WGPUStoreOp_Store;
- color_attachment.clearValue = {0.0, 0.0, 0.0, 1.0};
WGPURenderPassDescriptor pass_desc = {};
pass_desc.colorAttachmentCount = 1;
pass_desc.colorAttachments = &color_attachment;
- WGPURenderPassEncoder pass = wgpuCommandEncoderBeginRenderPass(encoder, &pass_desc);
+ WGPURenderPassEncoder pass =
+ wgpuCommandEncoderBeginRenderPass(encoder, &pass_desc);
wgpuRenderPassEncoderSetPipeline(pass, pipeline_);
wgpuRenderPassEncoderSetBindGroup(pass, 0, bind_group_, 0, nullptr);
wgpuRenderPassEncoderDraw(pass, 3, 1, 0, 0);
diff --git a/src/effects/peak_meter_effect.h b/src/effects/peak_meter_effect.h
index 905bcda..e397a71 100644
--- a/src/effects/peak_meter_effect.h
+++ b/src/effects/peak_meter_effect.h
@@ -5,15 +5,14 @@
#include "gpu/effect.h"
#include "gpu/uniform_helper.h"
-class PeakMeterEffect : public Effect {
+class PeakMeter : public Effect {
public:
- PeakMeterEffect(const GpuContext& ctx,
- const std::vector<std::string>& inputs,
- const std::vector<std::string>& outputs);
- ~PeakMeterEffect() override;
+ PeakMeter(const GpuContext& ctx, const std::vector<std::string>& inputs,
+ const std::vector<std::string>& outputs, float start_time,
+ float end_time);
+ ~PeakMeter() override;
- void render(WGPUCommandEncoder encoder,
- const UniformsSequenceParams& params,
+ void render(WGPUCommandEncoder encoder, const UniformsSequenceParams& params,
NodeRegistry& nodes) override;
private:
diff --git a/src/effects/placeholder_effect.cc b/src/effects/placeholder_effect.cc
index d8852da..3367f1c 100644
--- a/src/effects/placeholder_effect.cc
+++ b/src/effects/placeholder_effect.cc
@@ -1,26 +1,27 @@
-// Placeholder effect v2 implementation - logs TODO warning once
+// Placeholder effect implementation - logs TODO warning once
#include "effects/placeholder_effect.h"
-#include "util/fatal_error.h"
+#include "effects/shaders.h"
#include "gpu/post_process_helper.h"
-#include "gpu/shaders.h"
+#include "util/fatal_error.h"
#include <cstdio>
-PlaceholderEffect::PlaceholderEffect(const GpuContext& ctx,
- const std::vector<std::string>& inputs,
- const std::vector<std::string>& outputs,
- const char* placeholder_name)
- : Effect(ctx, inputs, outputs), pipeline_(nullptr), bind_group_(nullptr),
- sampler_(nullptr), name_(placeholder_name) {
+Placeholder::Placeholder(const GpuContext& ctx,
+ const std::vector<std::string>& inputs,
+ const std::vector<std::string>& outputs,
+ float start_time, float end_time,
+ const char* placeholder_name)
+ : Effect(ctx, inputs, outputs, start_time, end_time), pipeline_(nullptr),
+ bind_group_(nullptr), sampler_(nullptr), name_(placeholder_name) {
// Log once on construction
- fprintf(stderr, "TODO: %s not yet ported to v2, using passthrough\n", name_);
+ fprintf(stderr, "TODO: %s not yet implemented, using passthrough\n", name_);
// Headless mode: skip GPU resource creation (compiled out in STRIP_ALL)
HEADLESS_RETURN_IF_NULL(ctx_.device);
uniforms_buffer_.init(ctx_.device);
- pipeline_ = create_post_process_pipeline(ctx_.device, WGPUTextureFormat_RGBA8Unorm,
- passthrough_v2_shader_wgsl);
+ pipeline_ = create_post_process_pipeline(
+ ctx_.device, WGPUTextureFormat_RGBA8Unorm, passthrough_shader_wgsl);
WGPUSamplerDescriptor sampler_desc = {};
sampler_desc.addressModeU = WGPUAddressMode_ClampToEdge;
@@ -33,9 +34,9 @@ PlaceholderEffect::PlaceholderEffect(const GpuContext& ctx,
sampler_ = wgpuDeviceCreateSampler(ctx_.device, &sampler_desc);
}
-void PlaceholderEffect::render(WGPUCommandEncoder encoder,
- const UniformsSequenceParams& params,
- NodeRegistry& nodes) {
+void Placeholder::render(WGPUCommandEncoder encoder,
+ const UniformsSequenceParams& params,
+ NodeRegistry& nodes) {
WGPUTextureView input_view = nodes.get_view(input_nodes_[0]);
WGPUTextureView output_view = nodes.get_view(output_nodes_[0]);
@@ -44,19 +45,15 @@ void PlaceholderEffect::render(WGPUCommandEncoder encoder,
pp_update_bind_group(ctx_.device, pipeline_, &bind_group_, input_view,
uniforms_buffer_.get(), {nullptr, 0});
- WGPURenderPassColorAttachment color_attachment = {
- .view = output_view,
- .depthSlice = WGPU_DEPTH_SLICE_UNDEFINED,
- .loadOp = WGPULoadOp_Clear,
- .storeOp = WGPUStoreOp_Store,
- .clearValue = {0.0, 0.0, 0.0, 1.0}
- };
+ WGPURenderPassColorAttachment color_attachment = {};
+ gpu_init_color_attachment(color_attachment, output_view);
WGPURenderPassDescriptor pass_desc = {};
pass_desc.colorAttachmentCount = 1;
pass_desc.colorAttachments = &color_attachment;
- WGPURenderPassEncoder pass = wgpuCommandEncoderBeginRenderPass(encoder, &pass_desc);
+ WGPURenderPassEncoder pass =
+ wgpuCommandEncoderBeginRenderPass(encoder, &pass_desc);
wgpuRenderPassEncoderSetPipeline(pass, pipeline_);
wgpuRenderPassEncoderSetBindGroup(pass, 0, bind_group_, 0, nullptr);
wgpuRenderPassEncoderDraw(pass, 3, 1, 0, 0);
diff --git a/src/effects/placeholder_effect.h b/src/effects/placeholder_effect.h
index f7917ab..24cf3f4 100644
--- a/src/effects/placeholder_effect.h
+++ b/src/effects/placeholder_effect.h
@@ -6,11 +6,11 @@
#include "gpu/effect.h"
#include "gpu/uniform_helper.h"
-class PlaceholderEffect : public Effect {
+class Placeholder : public Effect {
public:
- PlaceholderEffect(const GpuContext& ctx, const std::vector<std::string>& inputs,
- const std::vector<std::string>& outputs,
- const char* placeholder_name = "UnknownEffect");
+ Placeholder(const GpuContext& ctx, const std::vector<std::string>& inputs,
+ const std::vector<std::string>& outputs, float start_time,
+ float end_time, const char* placeholder_name = "UnknownEffect");
void render(WGPUCommandEncoder encoder, const UniformsSequenceParams& params,
NodeRegistry& nodes) override;
@@ -22,4 +22,3 @@ class PlaceholderEffect : public Effect {
UniformBuffer<UniformsSequenceParams> uniforms_buffer_;
const char* name_;
};
-
diff --git a/src/effects/rotating_cube_effect.cc b/src/effects/rotating_cube_effect.cc
index 57f0a83..6c350a7 100644
--- a/src/effects/rotating_cube_effect.cc
+++ b/src/effects/rotating_cube_effect.cc
@@ -1,16 +1,17 @@
// This file is part of the 64k demo project.
-// It implements RotatingCubeEffect (simplified v2 port).
+// It implements RotatingCube.
-#include "util/fatal_error.h"
#include "effects/rotating_cube_effect.h"
+#include "effects/shaders.h"
#include "gpu/bind_group_builder.h"
#include "gpu/gpu.h"
-#include "gpu/shaders.h"
+#include "util/fatal_error.h"
-RotatingCubeEffect::RotatingCubeEffect(const GpuContext& ctx,
- const std::vector<std::string>& inputs,
- const std::vector<std::string>& outputs)
- : Effect(ctx, inputs, outputs), depth_node_(outputs[0] + "_depth") {
+RotatingCube::RotatingCube(const GpuContext& ctx,
+ const std::vector<std::string>& inputs,
+ const std::vector<std::string>& outputs, float start_time,
+ float end_time)
+ : Effect(ctx, inputs, outputs, start_time, end_time), depth_node_(outputs[0] + "_depth") {
// Headless mode: skip GPU resource creation (compiled out in STRIP_ALL)
HEADLESS_RETURN_IF_NULL(ctx_.device);
@@ -39,10 +40,10 @@ RotatingCubeEffect::RotatingCubeEffect(const GpuContext& ctx,
WGPUPipelineLayout pipeline_layout =
wgpuDeviceCreatePipelineLayout(ctx_.device, &pl_desc);
- // Load shader (TODO: create rotating_cube_v2.wgsl)
+ // Load shader
WGPUShaderSourceWGSL wgsl_src = {};
wgsl_src.chain.sType = WGPUSType_ShaderSourceWGSL;
- wgsl_src.code = str_view(rotating_cube_v2_wgsl);
+ wgsl_src.code = str_view(rotating_cube_wgsl);
WGPUShaderModuleDescriptor shader_desc = {};
shader_desc.nextInChain = &wgsl_src.chain;
@@ -100,21 +101,21 @@ RotatingCubeEffect::RotatingCubeEffect(const GpuContext& ctx,
wgpuBindGroupLayoutRelease(bgl);
}
-RotatingCubeEffect::~RotatingCubeEffect() {
+RotatingCube::~RotatingCube() {
if (bind_group_)
wgpuBindGroupRelease(bind_group_);
if (pipeline_)
wgpuRenderPipelineRelease(pipeline_);
}
-void RotatingCubeEffect::declare_nodes(NodeRegistry& registry) {
+void RotatingCube::declare_nodes(NodeRegistry& registry) {
// Declare depth buffer node
registry.declare_node(depth_node_, NodeType::DEPTH24, -1, -1);
}
-void RotatingCubeEffect::render(WGPUCommandEncoder encoder,
- const UniformsSequenceParams& params,
- NodeRegistry& nodes) {
+void RotatingCube::render(WGPUCommandEncoder encoder,
+ const UniformsSequenceParams& params,
+ NodeRegistry& nodes) {
rotation_ += 0.016f * 1.5f;
// Camera setup
@@ -138,7 +139,8 @@ void RotatingCubeEffect::render(WGPUCommandEncoder encoder,
const Uniforms uniforms = {
.view_proj = view_proj,
.inv_view_proj = view_proj.inverse(),
- .camera_pos_time = vec4(camera_pos.x, camera_pos.y, camera_pos.z, params.time),
+ .camera_pos_time =
+ vec4(camera_pos.x, camera_pos.y, camera_pos.z, params.time),
.params = vec4(1.0f, 0.0f, 0.0f, 0.0f),
.resolution = params.resolution,
.aspect_ratio = params.aspect_ratio,
@@ -156,6 +158,22 @@ void RotatingCubeEffect::render(WGPUCommandEncoder encoder,
wgpuQueueWriteBuffer(ctx_.queue, object_buffer_.buffer, 0, &obj_data,
sizeof(ObjectData));
+ // Blit input to output if compositing (not reading from source)
+ if (!input_nodes_.empty() && input_nodes_[0] != "source") {
+ WGPUTexture input_tex = nodes.get_texture(input_nodes_[0]);
+ WGPUTexture output_tex = nodes.get_texture(output_nodes_[0]);
+ if (input_tex && output_tex) {
+ GpuTextureCopyInfo src = {
+ .texture = input_tex, .mipLevel = 0, .aspect = WGPUTextureAspect_All};
+ GpuTextureCopyInfo dst = {.texture = output_tex,
+ .mipLevel = 0,
+ .aspect = WGPUTextureAspect_All};
+ WGPUExtent3D copy_size = {(uint32_t)params.resolution.x,
+ (uint32_t)params.resolution.y, 1};
+ wgpuCommandEncoderCopyTextureToTexture(encoder, &src, &dst, &copy_size);
+ }
+ }
+
// Get output views
WGPUTextureView color_view = nodes.get_view(output_nodes_[0]);
WGPUTextureView depth_view = nodes.get_view(depth_node_);
@@ -163,10 +181,13 @@ void RotatingCubeEffect::render(WGPUCommandEncoder encoder,
// Render pass with depth
WGPURenderPassColorAttachment color_attachment = {
.view = color_view,
+ #if !defined(DEMO_CROSS_COMPILE_WIN32)
.depthSlice = WGPU_DEPTH_SLICE_UNDEFINED,
- .loadOp = WGPULoadOp_Clear,
+#endif
+ // .loadOp = WGPULoadOp_Clear,
+ .loadOp = WGPULoadOp_Load,
.storeOp = WGPUStoreOp_Store,
- .clearValue = {0.0, 0.0, 0.0, 1.0}};
+ .clearValue = {0.0, 0.0, 0.0, 0.0}};
WGPURenderPassDepthStencilAttachment depth_attachment = {
.view = depth_view,
@@ -174,15 +195,16 @@ void RotatingCubeEffect::render(WGPUCommandEncoder encoder,
.depthStoreOp = WGPUStoreOp_Discard,
.depthClearValue = 1.0f};
- WGPURenderPassDescriptor pass_desc = {
- .colorAttachmentCount = 1,
- .colorAttachments = &color_attachment,
- .depthStencilAttachment = &depth_attachment};
+ WGPURenderPassDescriptor pass_desc = {.colorAttachmentCount = 1,
+ .colorAttachments = &color_attachment,
+ .depthStencilAttachment =
+ &depth_attachment};
- WGPURenderPassEncoder pass = wgpuCommandEncoderBeginRenderPass(encoder, &pass_desc);
+ WGPURenderPassEncoder pass =
+ wgpuCommandEncoderBeginRenderPass(encoder, &pass_desc);
wgpuRenderPassEncoderSetPipeline(pass, pipeline_);
wgpuRenderPassEncoderSetBindGroup(pass, 0, bind_group_, 0, nullptr);
- wgpuRenderPassEncoderDraw(pass, 36, 1, 0, 0); // 36 vertices for cube
+ wgpuRenderPassEncoderDraw(pass, 36, 1, 0, 0); // 36 vertices for cube
wgpuRenderPassEncoderEnd(pass);
wgpuRenderPassEncoderRelease(pass);
}
diff --git a/src/effects/rotating_cube_effect.h b/src/effects/rotating_cube_effect.h
index 1c0155a..e773025 100644
--- a/src/effects/rotating_cube_effect.h
+++ b/src/effects/rotating_cube_effect.h
@@ -8,16 +8,15 @@
#include "gpu/uniform_helper.h"
#include "util/mini_math.h"
-class RotatingCubeEffect : public Effect {
+class RotatingCube : public Effect {
public:
- RotatingCubeEffect(const GpuContext& ctx,
- const std::vector<std::string>& inputs,
- const std::vector<std::string>& outputs);
- ~RotatingCubeEffect() override;
+ RotatingCube(const GpuContext& ctx, const std::vector<std::string>& inputs,
+ const std::vector<std::string>& outputs, float start_time,
+ float end_time);
+ ~RotatingCube() override;
void declare_nodes(NodeRegistry& registry) override;
- void render(WGPUCommandEncoder encoder,
- const UniformsSequenceParams& params,
+ void render(WGPUCommandEncoder encoder, const UniformsSequenceParams& params,
NodeRegistry& nodes) override;
private:
diff --git a/src/gpu/shaders.cc b/src/effects/shaders.cc
index 4017726..d181632 100644
--- a/src/gpu/shaders.cc
+++ b/src/effects/shaders.cc
@@ -1,22 +1,16 @@
// This file is part of the 64k demo project.
// It defines WGSL shader code for various effects.
-#include "demo_effects.h"
+#include "effects/shaders.h"
+#include "gpu/shader_composer.h"
+#include "util/asset_manager.h"
#if defined(USE_TEST_ASSETS)
-
#include "test_assets.h"
-
#else
-
#include "generated/assets.h"
-
#endif
-#include "gpu/shader_composer.h"
-
-#include "util/asset_manager.h"
-
void InitShaderComposer() {
auto& sc = ShaderComposer::Get();
@@ -79,106 +73,36 @@ void InitShaderComposer() {
}
// Helper to get asset string or empty string
-
static const char* SafeGetAsset(AssetId id) {
const uint8_t* data = GetAsset(id);
-
return data ? (const char*)data : "";
}
-const char* main_shader_wgsl = SafeGetAsset(AssetId::ASSET_SHADER_MAIN);
-
+// Effect shaders
+const char* passthrough_shader_wgsl =
+ SafeGetAsset(AssetId::ASSET_SHADER_PASSTHROUGH_V2);
+const char* gaussian_blur_shader_wgsl =
+ SafeGetAsset(AssetId::ASSET_SHADER_GAUSSIAN_BLUR_V2);
+const char* heptagon_shader_wgsl =
+ SafeGetAsset(AssetId::ASSET_SHADER_HEPTAGON_V2);
const char* particle_compute_wgsl =
-
SafeGetAsset(AssetId::ASSET_SHADER_PARTICLE_COMPUTE);
-
const char* particle_render_wgsl =
-
SafeGetAsset(AssetId::ASSET_SHADER_PARTICLE_RENDER);
+const char* rotating_cube_wgsl =
+ SafeGetAsset(AssetId::ASSET_SHADER_ROTATING_CUBE_V2);
+const char* flash_shader_wgsl = SafeGetAsset(AssetId::ASSET_SHADER_FLASH);
-const char* passthrough_shader_wgsl =
-
- SafeGetAsset(AssetId::ASSET_SHADER_PASSTHROUGH);
-
-const char* ellipse_shader_wgsl =
-
- SafeGetAsset(AssetId::ASSET_SHADER_ELLIPSE);
-
-const char* particle_spray_compute_wgsl =
-
- SafeGetAsset(AssetId::ASSET_SHADER_PARTICLE_SPRAY_COMPUTE);
-
-const char* gaussian_blur_shader_wgsl =
-
- SafeGetAsset(AssetId::ASSET_SHADER_GAUSSIAN_BLUR);
-
-const char* solarize_shader_wgsl =
-
- SafeGetAsset(AssetId::ASSET_SHADER_SOLARIZE);
-
-// const char* scene1_shader_wgsl =
-// SafeGetAsset(AssetId::ASSET_SHADER_SCENE1);
-
-// const char* sdf_test_shader_wgsl =
-// SafeGetAsset(AssetId::ASSET_SHADER_SDF_TEST);
-
-const char* distort_shader_wgsl =
-
- SafeGetAsset(AssetId::ASSET_SHADER_DISTORT);
-
-const char* chroma_aberration_shader_wgsl =
-
- SafeGetAsset(AssetId::ASSET_SHADER_CHROMA_ABERRATION);
-
-// const char* cnn_layer_shader_wgsl =
-// SafeGetAsset(AssetId::ASSET_SHADER_CNN_LAYER);
-
+// Compute shaders
const char* gen_noise_compute_wgsl =
-
SafeGetAsset(AssetId::ASSET_SHADER_COMPUTE_GEN_NOISE);
-
const char* gen_perlin_compute_wgsl =
-
SafeGetAsset(AssetId::ASSET_SHADER_COMPUTE_GEN_PERLIN);
-
const char* gen_grid_compute_wgsl =
-
SafeGetAsset(AssetId::ASSET_SHADER_COMPUTE_GEN_GRID);
-
#if !defined(STRIP_GPU_COMPOSITE)
const char* gen_blend_compute_wgsl =
-
SafeGetAsset(AssetId::ASSET_SHADER_COMPUTE_GEN_BLEND);
-
const char* gen_mask_compute_wgsl =
-
SafeGetAsset(AssetId::ASSET_SHADER_COMPUTE_GEN_MASK);
#endif
-
-const char* vignette_shader_wgsl =
-
- SafeGetAsset(AssetId::ASSET_SHADER_VIGNETTE);
-
-// Sequence v2 shaders
-const char* passthrough_v2_shader_wgsl =
-
- SafeGetAsset(AssetId::ASSET_SHADER_PASSTHROUGH_V2);
-
-const char* gaussian_blur_v2_shader_wgsl =
-
- SafeGetAsset(AssetId::ASSET_SHADER_GAUSSIAN_BLUR_V2);
-
-const char* heptagon_v2_shader_wgsl =
-
- SafeGetAsset(AssetId::ASSET_SHADER_HEPTAGON_V2);
-
-const char* particle_compute_v2_wgsl =
- SafeGetAsset(AssetId::ASSET_SHADER_PARTICLE_COMPUTE);
-
-const char* particle_render_v2_wgsl =
- SafeGetAsset(AssetId::ASSET_SHADER_PARTICLE_RENDER);
-
-const char* rotating_cube_v2_wgsl =
- SafeGetAsset(AssetId::ASSET_SHADER_ROTATING_CUBE_V2);
-
-const char* flash_shader_wgsl = SafeGetAsset(AssetId::ASSET_SHADER_FLASH);
diff --git a/src/effects/shaders.h b/src/effects/shaders.h
new file mode 100644
index 0000000..b8700f5
--- /dev/null
+++ b/src/effects/shaders.h
@@ -0,0 +1,25 @@
+// This file is part of the 64k demo project.
+// It declares the WGSL shader strings and initialization function.
+
+#pragma once
+
+// Initializes the ShaderComposer with snippet assets.
+void InitShaderComposer();
+
+// Effect shaders
+extern const char* passthrough_shader_wgsl;
+extern const char* gaussian_blur_shader_wgsl;
+extern const char* heptagon_shader_wgsl;
+extern const char* particle_compute_wgsl;
+extern const char* particle_render_wgsl;
+extern const char* rotating_cube_wgsl;
+extern const char* flash_shader_wgsl;
+
+// Compute shaders
+extern const char* gen_noise_compute_wgsl;
+extern const char* gen_perlin_compute_wgsl;
+extern const char* gen_grid_compute_wgsl;
+#if !defined(STRIP_GPU_COMPOSITE)
+extern const char* gen_blend_compute_wgsl;
+extern const char* gen_mask_compute_wgsl;
+#endif
diff --git a/src/gpu/bind_group_builder.h b/src/gpu/bind_group_builder.h
index 49b7ebe..7481f34 100644
--- a/src/gpu/bind_group_builder.h
+++ b/src/gpu/bind_group_builder.h
@@ -94,7 +94,8 @@ class BindGroupLayoutBuilder {
}
WGPUBindGroupLayout build(WGPUDevice device) {
- // Headless mode: skip bind group layout creation (compiled out in STRIP_ALL)
+ // Headless mode: skip bind group layout creation (compiled out in
+ // STRIP_ALL)
HEADLESS_RETURN_VAL_IF_NULL(device, nullptr);
WGPUBindGroupLayoutDescriptor desc{};
desc.entryCount = entries_.size();
diff --git a/src/gpu/demo_effects.cc b/src/gpu/demo_effects.cc
index d9c5964..5114e3a 100644
--- a/src/gpu/demo_effects.cc
+++ b/src/gpu/demo_effects.cc
@@ -1,6 +1,4 @@
// This file is part of the 64k demo project.
// Central include for all effect implementations.
-// Individual effects are in src/effects/*_v2.{h,cc}
-// Timeline management is in src/generated/timeline.cc (v2)
#include "gpu/demo_effects.h"
diff --git a/src/gpu/demo_effects.h b/src/gpu/demo_effects.h
index 999deb1..2825891 100644
--- a/src/gpu/demo_effects.h
+++ b/src/gpu/demo_effects.h
@@ -8,15 +8,16 @@
#include "3d/renderer.h"
#include "3d/scene.h"
-// Base effect classes (v2)
+// Base effect classes
+#include "effects/shaders.h"
#include "gpu/effect.h"
#include "gpu/post_process_helper.h"
#include "gpu/sequence.h"
-#include "gpu/shaders.h"
#include "gpu/texture_manager.h"
#include "gpu/uniform_helper.h"
-// Individual Effect Headers (v2)
+// Individual Effect Headers
+#include "effects/flash_effect.h"
#include "effects/gaussian_blur_effect.h"
#include "effects/heptagon_effect.h"
#include "effects/hybrid3_d_effect.h"
@@ -25,15 +26,8 @@
#include "effects/peak_meter_effect.h"
#include "effects/placeholder_effect.h"
#include "effects/rotating_cube_effect.h"
-#include "effects/flash_effect.h"
-// TODO: Port CNN effects to v2
+// TODO: Port CNN effects
// #include "../../cnn_v1/src/cnn_v1_effect.h"
// #include "../../cnn_v2/src/cnn_v2_effect.h"
#include <memory>
-
-// Auto-generated functions from sequence compiler v2
-// See generated/timeline.h for:
-// - InitializeV2Sequences()
-// - GetActiveV2Sequence()
-// - RenderV2Timeline()
diff --git a/src/gpu/effect.cc b/src/gpu/effect.cc
index e4d3a90..752dd84 100644
--- a/src/gpu/effect.cc
+++ b/src/gpu/effect.cc
@@ -1,11 +1,57 @@
// Effect implementation
#include "gpu/effect.h"
+#include "gpu/gpu.h"
+#include "gpu/sequence.h"
#include "util/fatal_error.h"
Effect::Effect(const GpuContext& ctx, const std::vector<std::string>& inputs,
- const std::vector<std::string>& outputs)
- : ctx_(ctx), input_nodes_(inputs), output_nodes_(outputs) {
+ const std::vector<std::string>& outputs, float start_time,
+ float end_time)
+ : ctx_(ctx), input_nodes_(inputs), output_nodes_(outputs),
+ start_time_(start_time), end_time_(end_time) {
FATAL_CHECK(!inputs.empty(), "Effect must have at least one input\n");
FATAL_CHECK(!outputs.empty(), "Effect must have at least one output\n");
+ FATAL_CHECK(start_time <= end_time, "Invalid time range: %f > %f\n",
+ start_time, end_time);
+}
+
+void Effect::dispatch_render(WGPUCommandEncoder encoder,
+ const UniformsSequenceParams& params,
+ NodeRegistry& nodes) {
+ // Check if effect is active at current time
+ const bool active =
+ (params.time >= start_time_ && params.time < end_time_);
+
+ // Auto-passthrough for 1:1 input/output effects outside active range
+ if (!active && input_nodes_.size() == 1 && output_nodes_.size() == 1) {
+ blit_input_to_output(encoder, nodes);
+ } else if (active) {
+ render(encoder, params, nodes);
+ }
+ // Multi-output effects: output undefined when inactive (validated at compile time)
+}
+
+void Effect::blit_input_to_output(WGPUCommandEncoder encoder,
+ NodeRegistry& nodes) {
+ HEADLESS_RETURN_IF_NULL(encoder);
+
+ WGPUTexture src = nodes.get_texture(input_nodes_[0]);
+ WGPUTexture dst = nodes.get_texture(output_nodes_[0]);
+
+ // Skip passthrough if textures are external (source/sink) or invalid
+ if (!src || !dst) {
+ return;
+ }
+
+ GpuTextureCopyInfo src_copy = {
+ .texture = src, .mipLevel = 0, .origin = {0, 0, 0}};
+ GpuTextureCopyInfo dst_copy = {
+ .texture = dst, .mipLevel = 0, .origin = {0, 0, 0}};
+
+ WGPUExtent3D extent = {(unsigned int)(width_),
+ (unsigned int)(height_), 1};
+
+ wgpuCommandEncoderCopyTextureToTexture(encoder, &src_copy, &dst_copy,
+ &extent);
}
diff --git a/src/gpu/effect.h b/src/gpu/effect.h
index d40e750..f5cdf2d 100644
--- a/src/gpu/effect.h
+++ b/src/gpu/effect.h
@@ -14,7 +14,8 @@ class NodeRegistry;
class Effect {
public:
Effect(const GpuContext& ctx, const std::vector<std::string>& inputs,
- const std::vector<std::string>& outputs);
+ const std::vector<std::string>& outputs, float start_time,
+ float end_time);
virtual ~Effect() = default;
// Optional: Declare temporary nodes (e.g., multi-pass intermediate buffers)
@@ -22,12 +23,15 @@ class Effect {
(void)registry;
}
- // Render effect (multi-input/multi-output)
+ // Automatic passthrough outside [start, end]
+ void dispatch_render(WGPUCommandEncoder encoder,
+ const UniformsSequenceParams& params,
+ NodeRegistry& nodes);
+
virtual void render(WGPUCommandEncoder encoder,
const UniformsSequenceParams& params,
NodeRegistry& nodes) = 0;
- // Resize notification
virtual void resize(int width, int height) {
width_ = width;
height_ = height;
@@ -46,5 +50,12 @@ class Effect {
std::vector<std::string> output_nodes_;
int width_ = 1280;
int height_ = 720;
+
+ private:
+ float start_time_;
+ float end_time_;
+
+ // Auto-passthrough helper for 1:1 input/output effects
+ void blit_input_to_output(WGPUCommandEncoder encoder, NodeRegistry& nodes);
};
#endif // EFFECT_H
diff --git a/src/gpu/gpu.cc b/src/gpu/gpu.cc
index 805e555..2226889 100644
--- a/src/gpu/gpu.cc
+++ b/src/gpu/gpu.cc
@@ -3,9 +3,9 @@
// Driven by audio peaks for synchronized visual effects.
#include "gpu.h"
+#include "effects/shaders.h"
#include "generated/timeline.h"
#include "gpu/shader_composer.h"
-#include "gpu/shaders.h"
#include "platform/platform.h"
#include <cassert>
diff --git a/src/gpu/gpu.h b/src/gpu/gpu.h
index 41eeb29..9a3fd38 100644
--- a/src/gpu/gpu.h
+++ b/src/gpu/gpu.h
@@ -1,27 +1,23 @@
// This file is part of the 64k demo project.
-// It defines the public interface for the GPU rendering system.
-// Coordinates WebGPU lifecycle and draw calls.
+// GPU rendering system interface.
#pragma once
#include "platform/platform.h"
-struct PlatformState; // Forward declaration
+struct PlatformState;
-// GPU context bundling device, queue, and surface format
struct GpuContext {
WGPUDevice device;
WGPUQueue queue;
WGPUTextureFormat format;
};
-// Basic wrapper for WebGPU buffers
struct GpuBuffer {
WGPUBuffer buffer;
size_t size;
};
-// Encapsulates a compute operation
struct ComputePass {
WGPUComputePipeline pipeline;
WGPUBindGroup bind_group;
@@ -30,7 +26,6 @@ struct ComputePass {
uint32_t workgroup_size_z;
};
-// Encapsulates a render operation
struct RenderPass {
WGPURenderPipeline pipeline;
WGPUBindGroup bind_group;
@@ -48,33 +43,35 @@ WGPUSurface gpu_get_surface();
const GpuContext* gpu_get_context();
-// Placeholder for GPU performance capture.
-// This define can be controlled via CMake to conditionally enable profiling
-// code. #define ENABLE_GPU_PERF_CAPTURE
-
-// Helper functions (exposed for internal/future use)
struct ResourceBinding {
GpuBuffer buffer;
- WGPUBufferBindingType type; // e.g., WGPUBufferBindingType_Uniform,
- // WGPUBufferBindingType_Storage
+ WGPUBufferBindingType type;
};
-// Cross-platform helper for color attachment initialization
inline void gpu_init_color_attachment(WGPURenderPassColorAttachment& attachment,
WGPUTextureView view) {
attachment.view = view;
attachment.loadOp = WGPULoadOp_Clear;
attachment.storeOp = WGPUStoreOp_Store;
attachment.clearValue = {0.0f, 0.0f, 0.0f, 1.0f};
+#if !defined(DEMO_CROSS_COMPILE_WIN32)
attachment.depthSlice = WGPU_DEPTH_SLICE_UNDEFINED;
+#endif
}
-// Texture creation helper
struct TextureWithView {
WGPUTexture texture;
WGPUTextureView view;
};
+#if defined(DEMO_CROSS_COMPILE_WIN32)
+using GpuTextureCopyInfo = WGPUImageCopyTexture;
+using GpuTextureDataLayout = WGPUTextureDataLayout;
+#else
+using GpuTextureCopyInfo = WGPUTexelCopyTextureInfo;
+using GpuTextureDataLayout = WGPUTexelCopyBufferLayout;
+#endif
+
GpuBuffer gpu_create_buffer(WGPUDevice device, size_t size, uint32_t usage,
const void* data = nullptr);
TextureWithView gpu_create_texture_2d(WGPUDevice device, uint32_t width,
diff --git a/src/gpu/headless_gpu.cc b/src/gpu/gpu_headless.cc
index e6995b2..e6995b2 100644
--- a/src/gpu/headless_gpu.cc
+++ b/src/gpu/gpu_headless.cc
diff --git a/src/gpu/stub_gpu.cc b/src/gpu/gpu_stub.cc
index d889666..d889666 100644
--- a/src/gpu/stub_gpu.cc
+++ b/src/gpu/gpu_stub.cc
diff --git a/src/gpu/post_process_helper.cc b/src/gpu/post_process_helper.cc
index 281fde6..9e7803c 100644
--- a/src/gpu/post_process_helper.cc
+++ b/src/gpu/post_process_helper.cc
@@ -41,9 +41,9 @@ WGPURenderPipeline create_post_process_pipeline(WGPUDevice device,
}
// Helper to create a simple post-processing pipeline (no effect params)
-WGPURenderPipeline create_post_process_pipeline_simple(WGPUDevice device,
- WGPUTextureFormat format,
- const char* shader_code) {
+WGPURenderPipeline
+create_post_process_pipeline_simple(WGPUDevice device, WGPUTextureFormat format,
+ const char* shader_code) {
// Headless mode: skip pipeline creation (compiled out in STRIP_ALL)
HEADLESS_RETURN_VAL_IF_NULL(device, nullptr);
diff --git a/src/gpu/post_process_helper.h b/src/gpu/post_process_helper.h
index 963f671..811d0e4 100644
--- a/src/gpu/post_process_helper.h
+++ b/src/gpu/post_process_helper.h
@@ -7,26 +7,21 @@
#include "gpu/sequence.h"
#include "util/mini_math.h"
-// Use UniformsSequenceParams (defined in sequence.h) for post-process effects
-
// Standard post-process bind group layout (group 0):
-#define PP_BINDING_SAMPLER 0 // Sampler for input texture
-#define PP_BINDING_TEXTURE 1 // Input texture (previous render pass)
-#define PP_BINDING_UNIFORMS 2 // Custom uniforms buffer
-#define PP_BINDING_EFFECT_PARAMS 3 // Effect-specific parameters
+#define PP_BINDING_SAMPLER 0
+#define PP_BINDING_TEXTURE 1
+#define PP_BINDING_UNIFORMS 2
+#define PP_BINDING_EFFECT_PARAMS 3
-// Helper to create a standard post-processing pipeline
-// Uniforms are accessible to both vertex and fragment shaders
WGPURenderPipeline create_post_process_pipeline(WGPUDevice device,
WGPUTextureFormat format,
const char* shader_code);
-// Helper to create a simple post-processing pipeline (no effect params, 3 bindings only)
+// No effect params, 3 bindings only
WGPURenderPipeline create_post_process_pipeline_simple(WGPUDevice device,
WGPUTextureFormat format,
const char* shader_code);
-// Helper to update bind group for post-processing effects
void pp_update_bind_group(WGPUDevice device, WGPURenderPipeline pipeline,
WGPUBindGroup* bind_group, WGPUTextureView input_view,
GpuBuffer uniforms, GpuBuffer effect_params);
diff --git a/src/gpu/sdf_effect.h b/src/gpu/sdf_effect.h
index aacea69..12ea556 100644
--- a/src/gpu/sdf_effect.h
+++ b/src/gpu/sdf_effect.h
@@ -1,5 +1,5 @@
// This file is part of the 64k demo project.
-// It defines SDFEffect base class for raymarching effects.
+// SDF raymarching effect base class.
#pragma once
@@ -8,11 +8,8 @@
#include "gpu/effect.h"
#include "gpu/uniform_helper.h"
-// Base class for SDF raymarching effects
-// Provides CameraParams uniform buffer and helper methods
-//
// Binding convention:
-// @group(0) @binding(2): UniformsSequenceParams (from Effect base)
+// @group(0) @binding(2): UniformsSequenceParams
// @group(0) @binding(3): CameraParams
// @group(0) @binding(4+): Per-effect custom parameters
class SDFEffect : public Effect {
@@ -23,7 +20,6 @@ class SDFEffect : public Effect {
virtual ~SDFEffect() = default;
- // Populate camera parameters from Camera object
void update_camera(const Camera& camera, float aspect_ratio) {
CameraParams params;
params.inv_view = camera.get_view_matrix().inverse();
@@ -34,7 +30,6 @@ class SDFEffect : public Effect {
camera_params_.update(ctx_.queue, params);
}
- // Populate camera parameters with custom values
void update_camera(const vec3& position, const vec3& target, const vec3& up,
float fov, float near_plane, float far_plane,
float aspect_ratio) {
diff --git a/src/gpu/sequence.cc b/src/gpu/sequence.cc
index 62c2933..901d560 100644
--- a/src/gpu/sequence.cc
+++ b/src/gpu/sequence.cc
@@ -42,9 +42,9 @@ NodeRegistry::~NodeRegistry() {
}
void NodeRegistry::declare_node(const std::string& name, NodeType type,
- int width, int height) {
- FATAL_CHECK(nodes_.find(name) == nodes_.end(),
- "Node already declared: %s\n", name.c_str());
+ int width, int height) {
+ FATAL_CHECK(nodes_.find(name) == nodes_.end(), "Node already declared: %s\n",
+ name.c_str());
if (width <= 0)
width = default_width_;
@@ -64,8 +64,8 @@ void NodeRegistry::declare_aliased_node(const std::string& name,
const std::string& alias_of) {
FATAL_CHECK(nodes_.find(alias_of) != nodes_.end(),
"Alias target does not exist: %s\n", alias_of.c_str());
- FATAL_CHECK(aliases_.find(name) == aliases_.end(), "Alias already exists: %s\n",
- name.c_str());
+ FATAL_CHECK(aliases_.find(name) == aliases_.end(),
+ "Alias already exists: %s\n", name.c_str());
aliases_[name] = alias_of;
}
@@ -92,6 +92,16 @@ NodeRegistry::get_output_views(const std::vector<std::string>& names) {
return views;
}
+WGPUTexture NodeRegistry::get_texture(const std::string& name) {
+ auto alias_it = aliases_.find(name);
+ if (alias_it != aliases_.end()) {
+ return get_texture(alias_it->second);
+ }
+ auto it = nodes_.find(name);
+ FATAL_CHECK(it != nodes_.end(), "Node not found: %s\n", name.c_str());
+ return it->second.texture;
+}
+
void NodeRegistry::resize(int width, int height) {
default_width_ = width;
default_height_ = height;
@@ -121,7 +131,7 @@ bool NodeRegistry::has_node(const std::string& name) const {
}
void NodeRegistry::set_external_view(const std::string& name,
- WGPUTextureView view) {
+ WGPUTextureView view) {
// Register external view (texture not owned by registry)
Node node = {};
node.view = view;
@@ -141,15 +151,25 @@ void NodeRegistry::create_texture(Node& node) {
switch (node.type) {
case NodeType::U8X4_NORM:
format = WGPUTextureFormat_RGBA8Unorm;
- usage = (WGPUTextureUsage)(WGPUTextureUsage_RenderAttachment | WGPUTextureUsage_TextureBinding);
+ usage =
+ (WGPUTextureUsage)(WGPUTextureUsage_RenderAttachment |
+ WGPUTextureUsage_TextureBinding |
+ WGPUTextureUsage_CopySrc | WGPUTextureUsage_CopyDst);
break;
case NodeType::F32X4:
format = WGPUTextureFormat_RGBA32Float;
- usage = (WGPUTextureUsage)(WGPUTextureUsage_RenderAttachment | WGPUTextureUsage_TextureBinding);
+ usage =
+ (WGPUTextureUsage)(WGPUTextureUsage_RenderAttachment |
+ WGPUTextureUsage_TextureBinding |
+ WGPUTextureUsage_CopySrc | WGPUTextureUsage_CopyDst);
break;
case NodeType::F16X8:
- format = WGPUTextureFormat_RGBA16Float; // WebGPU doesn't have 8-channel, use RGBA16
- usage = (WGPUTextureUsage)(WGPUTextureUsage_RenderAttachment | WGPUTextureUsage_TextureBinding);
+ format = WGPUTextureFormat_RGBA16Float; // WebGPU doesn't have 8-channel,
+ // use RGBA16
+ usage =
+ (WGPUTextureUsage)(WGPUTextureUsage_RenderAttachment |
+ WGPUTextureUsage_TextureBinding |
+ WGPUTextureUsage_CopySrc | WGPUTextureUsage_CopyDst);
break;
case NodeType::DEPTH24:
format = WGPUTextureFormat_Depth24Plus;
@@ -157,15 +177,16 @@ void NodeRegistry::create_texture(Node& node) {
break;
case NodeType::COMPUTE_F32:
format = WGPUTextureFormat_RGBA32Float;
- usage = (WGPUTextureUsage)(WGPUTextureUsage_StorageBinding | WGPUTextureUsage_TextureBinding);
+ usage = (WGPUTextureUsage)(WGPUTextureUsage_StorageBinding |
+ WGPUTextureUsage_TextureBinding);
break;
}
WGPUTextureDescriptor desc = {};
desc.usage = usage;
desc.dimension = WGPUTextureDimension_2D;
- desc.size = {static_cast<unsigned int>(node.width),
- static_cast<unsigned int>(node.height), 1};
+ desc.size = {(unsigned int)(node.width),
+ (unsigned int)(node.height), 1};
desc.format = format;
desc.mipLevelCount = 1;
desc.sampleCount = 1;
@@ -197,10 +218,11 @@ Sequence::Sequence(const GpuContext& ctx, int width, int height)
}
void Sequence::preprocess(float seq_time, float beat_time, float beat_phase,
- float audio_intensity) {
- params_.resolution = {static_cast<float>(width_), static_cast<float>(height_)};
+ float audio_intensity) {
+ params_.resolution = {(float)(width_),
+ (float)(height_)};
params_.aspect_ratio =
- static_cast<float>(width_) / static_cast<float>(height_);
+ (float)(width_) / (float)(height_);
params_.time = seq_time;
params_.beat_time = beat_time;
params_.beat_phase = beat_phase;
@@ -218,7 +240,7 @@ void Sequence::postprocess(WGPUCommandEncoder encoder) {
void Sequence::render_effects(WGPUCommandEncoder encoder) {
// Execute DAG in topological order (pre-sorted by compiler)
for (const auto& dag_node : effect_dag_) {
- dag_node.effect->render(encoder, params_, nodes_);
+ dag_node.effect->dispatch_render(encoder, params_, nodes_);
}
}
diff --git a/src/gpu/sequence.h b/src/gpu/sequence.h
index a33dedb..3bb770f 100644
--- a/src/gpu/sequence.h
+++ b/src/gpu/sequence.h
@@ -1,5 +1,4 @@
-// Sequence: Explicit node system with DAG effect routing
-// DAG-based effect routing with ping-pong optimization
+// Sequence: DAG-based effect routing with ping-pong optimization
#ifndef SEQUENCE_H
#define SEQUENCE_H
@@ -16,11 +15,11 @@
class Effect;
enum class NodeType {
- U8X4_NORM, // RGBAu8 normalized (0-1) - default Source/Sink
- F32X4, // RGBA float32
- F16X8, // 8-channel float16
- DEPTH24, // Depth buffer
- COMPUTE_F32, // Compute buffer
+ U8X4_NORM, // RGBAu8 (default Source/Sink)
+ F32X4,
+ F16X8,
+ DEPTH24,
+ COMPUTE_F32,
};
struct Node {
@@ -35,9 +34,9 @@ struct Node {
struct UniformsSequenceParams {
vec2 resolution;
float aspect_ratio;
- float time; // Per-sequence relative time
- float beat_time; // Musical beats
- float beat_phase; // Fractional beat 0.0-1.0
+ float time; // Per-sequence relative time
+ float beat_time; // Musical beats
+ float beat_phase; // Fractional beat 0.0-1.0
float audio_intensity;
float _pad;
};
@@ -49,26 +48,22 @@ class NodeRegistry {
NodeRegistry(WGPUDevice device, int default_width, int default_height);
~NodeRegistry();
- // Declare new node with explicit type/dimensions
void declare_node(const std::string& name, NodeType type, int width,
int height);
- // Declare aliased node (ping-pong optimization)
void declare_aliased_node(const std::string& name,
const std::string& alias_of);
- // Retrieve views
WGPUTextureView get_view(const std::string& name);
std::vector<WGPUTextureView>
get_output_views(const std::vector<std::string>& names);
- // Resize all nodes
+ WGPUTexture get_texture(const std::string& name);
+
void resize(int width, int height);
- // Check if node exists
bool has_node(const std::string& name) const;
- // Register external view (for source/sink managed externally)
void set_external_view(const std::string& name, WGPUTextureView view);
private:
@@ -76,7 +71,7 @@ class NodeRegistry {
int default_width_;
int default_height_;
std::map<std::string, Node> nodes_;
- std::map<std::string, std::string> aliases_; // name -> backing node name
+ std::map<std::string, std::string> aliases_;
void create_texture(Node& node);
};
@@ -85,7 +80,7 @@ struct EffectDAGNode {
std::shared_ptr<Effect> effect;
std::vector<std::string> input_nodes;
std::vector<std::string> output_nodes;
- int execution_order; // Topologically sorted
+ int execution_order;
};
class Sequence {
@@ -93,7 +88,6 @@ class Sequence {
Sequence(const GpuContext& ctx, int width, int height);
virtual ~Sequence() = default;
- // Virtual methods (most sequences use defaults)
virtual void preprocess(float seq_time, float beat_time, float beat_phase,
float audio_intensity);
virtual void postprocess(WGPUCommandEncoder encoder);
@@ -101,20 +95,16 @@ class Sequence {
void resize(int width, int height);
- // Initialize effect nodes (call at end of subclass constructor)
void init_effect_nodes();
- // Set surface texture view for rendering (sink node)
void set_sink_view(WGPUTextureView view) {
nodes_.set_external_view("sink", view);
}
- // Set source texture view (input framebuffer)
void set_source_view(WGPUTextureView view) {
nodes_.set_external_view("source", view);
}
- // Test accessor
const std::vector<EffectDAGNode>& get_effect_dag() const {
return effect_dag_;
}
diff --git a/src/gpu/shader_composer.h b/src/gpu/shader_composer.h
index d0972f2..90e1ec1 100644
--- a/src/gpu/shader_composer.h
+++ b/src/gpu/shader_composer.h
@@ -12,19 +12,16 @@ class ShaderComposer {
public:
static ShaderComposer& Get();
- // Register a snippet (e.g. "common_math", "sdf_primitives")
void RegisterSnippet(const std::string& name, const std::string& code);
using CompositionMap = std::map<std::string, std::string>;
- // Assemble a final shader string by prepending required snippets
- // and recursively resolving #include "snippet_name" directives.
- // Optional substitutions: map "placeholder_name" -> "actual_snippet_name"
+ // Resolves #include directives recursively
+ // substitutions: map "placeholder_name" -> "actual_snippet_name"
std::string Compose(const std::vector<std::string>& dependencies,
const std::string& main_code,
const CompositionMap& substitutions = {});
- // Verify all #include directives reference registered snippets
void VerifyIncludes() const;
private:
diff --git a/src/gpu/shaders.h b/src/gpu/shaders.h
deleted file mode 100644
index 4fee863..0000000
--- a/src/gpu/shaders.h
+++ /dev/null
@@ -1,39 +0,0 @@
-// This file is part of the 64k demo project.
-// It declares the WGSL shader strings and initialization function.
-
-#pragma once
-
-// Initializes the ShaderComposer with snippet assets.
-void InitShaderComposer();
-
-// Shader declarations (defined in shaders.cc)
-extern const char* main_shader_wgsl;
-extern const char* particle_compute_wgsl;
-extern const char* particle_render_wgsl;
-extern const char* passthrough_shader_wgsl;
-extern const char* ellipse_shader_wgsl;
-extern const char* particle_spray_compute_wgsl;
-extern const char* gaussian_blur_shader_wgsl;
-extern const char* solarize_shader_wgsl;
-extern const char* scene1_shader_wgsl;
-extern const char* sdf_test_shader_wgsl;
-extern const char* distort_shader_wgsl;
-extern const char* chroma_aberration_shader_wgsl;
-extern const char* vignette_shader_wgsl;
-extern const char* cnn_layer_shader_wgsl;
-extern const char* gen_noise_compute_wgsl;
-extern const char* gen_perlin_compute_wgsl;
-extern const char* gen_grid_compute_wgsl;
-#if !defined(STRIP_GPU_COMPOSITE)
-extern const char* gen_blend_compute_wgsl;
-extern const char* gen_mask_compute_wgsl;
-#endif
-
-// Sequence v2 shaders
-extern const char* passthrough_v2_shader_wgsl;
-extern const char* gaussian_blur_v2_shader_wgsl;
-extern const char* heptagon_v2_shader_wgsl;
-extern const char* particle_compute_v2_wgsl;
-extern const char* particle_render_v2_wgsl;
-extern const char* rotating_cube_v2_wgsl;
-extern const char* flash_shader_wgsl;
diff --git a/src/gpu/texture_manager.cc b/src/gpu/texture_manager.cc
index 5bca95b..bdeb508 100644
--- a/src/gpu/texture_manager.cc
+++ b/src/gpu/texture_manager.cc
@@ -2,22 +2,13 @@
// It implements the TextureManager.
#include "gpu/texture_manager.h"
+#include "gpu/gpu.h"
#include "gpu/shader_composer.h"
#include "platform/platform.h"
#include <cstdio>
#include <cstring>
#include <vector>
-#if defined(DEMO_CROSS_COMPILE_WIN32)
-// Old API
-#define WGPU_TEX_COPY_INFO WGPUImageCopyTexture
-#define WGPU_TEX_DATA_LAYOUT WGPUTextureDataLayout
-#else
-// New API
-#define WGPU_TEX_COPY_INFO WGPUTexelCopyTextureInfo
-#define WGPU_TEX_DATA_LAYOUT WGPUTexelCopyBufferLayout
-#endif
-
void TextureManager::init(WGPUDevice device, WGPUQueue queue) {
device_ = device;
queue_ = queue;
@@ -79,22 +70,18 @@ void TextureManager::create_texture(const std::string& name, int width,
tex_desc.format = WGPUTextureFormat_RGBA8Unorm;
tex_desc.mipLevelCount = 1;
tex_desc.sampleCount = 1;
-#if defined(DEMO_CROSS_COMPILE_WIN32)
- tex_desc.label = nullptr;
-#else
- tex_desc.label = {nullptr, 0};
-#endif
+ tex_desc.label = label_view(nullptr);
WGPUTexture texture = wgpuDeviceCreateTexture(device_, &tex_desc);
// 3. Upload Data
- WGPU_TEX_COPY_INFO destination = {};
+ GpuTextureCopyInfo destination = {};
destination.texture = texture;
destination.mipLevel = 0;
destination.origin = {0, 0, 0};
destination.aspect = WGPUTextureAspect_All;
- WGPU_TEX_DATA_LAYOUT source_layout = {};
+ GpuTextureDataLayout source_layout = {};
source_layout.offset = 0;
source_layout.bytesPerRow = width * 4;
source_layout.rowsPerImage = height;
diff --git a/src/gpu/texture_readback.cc b/src/gpu/texture_readback.cc
index bd3c79c..211beed 100644
--- a/src/gpu/texture_readback.cc
+++ b/src/gpu/texture_readback.cc
@@ -52,12 +52,12 @@ std::vector<uint8_t> read_texture_pixels(WGPUInstance instance,
.layout =
{
.bytesPerRow = aligned_bytes_per_row,
- .rowsPerImage = static_cast<uint32_t>(height),
+ .rowsPerImage = (uint32_t)(height),
},
};
- const WGPUExtent3D copy_size = {static_cast<uint32_t>(width),
- static_cast<uint32_t>(height), 1};
+ const WGPUExtent3D copy_size = {(uint32_t)(width),
+ (uint32_t)(height), 1};
wgpuCommandEncoderCopyTextureToBuffer(encoder, &src, &dst, &copy_size);
@@ -77,7 +77,7 @@ std::vector<uint8_t> read_texture_pixels(WGPUInstance instance,
// Win32: Old callback API
MapState map_state = {};
auto map_cb = [](WGPUBufferMapAsyncStatus status, void* userdata) {
- MapState* state = static_cast<MapState*>(userdata);
+ MapState* state = (MapState*)(userdata);
state->status = status;
state->done = true;
};
@@ -90,7 +90,7 @@ std::vector<uint8_t> read_texture_pixels(WGPUInstance instance,
void* userdata, void* user2) {
(void)message;
(void)user2;
- MapState* state = static_cast<MapState*>(userdata);
+ MapState* state = (MapState*)(userdata);
state->status = status;
state->done = true;
};
@@ -117,7 +117,7 @@ std::vector<uint8_t> read_texture_pixels(WGPUInstance instance,
}
// Copy data from mapped buffer (handle row padding)
- const uint8_t* mapped_data = static_cast<const uint8_t*>(
+ const uint8_t* mapped_data = (const uint8_t*)(
wgpuBufferGetConstMappedRange(staging, 0, buffer_size));
if (mapped_data) {
// If rows are aligned, copy row by row to remove padding
@@ -209,11 +209,11 @@ std::vector<uint8_t> texture_readback_fp16_to_u8(WGPUDevice device,
.layout =
{
.bytesPerRow = aligned_bytes_per_row,
- .rowsPerImage = static_cast<uint32_t>(height),
+ .rowsPerImage = (uint32_t)(height),
},
};
- const WGPUExtent3D copy_size = {static_cast<uint32_t>(width),
- static_cast<uint32_t>(height), 1};
+ const WGPUExtent3D copy_size = {(uint32_t)(width),
+ (uint32_t)(height), 1};
wgpuCommandEncoderCopyTextureToBuffer(encoder, &src, &dst, &copy_size);
WGPUCommandBuffer commands = wgpuCommandEncoderFinish(encoder, nullptr);
@@ -226,7 +226,7 @@ std::vector<uint8_t> texture_readback_fp16_to_u8(WGPUDevice device,
#if defined(DEMO_CROSS_COMPILE_WIN32)
MapState map_state = {};
auto map_cb = [](WGPUBufferMapAsyncStatus status, void* userdata) {
- MapState* state = static_cast<MapState*>(userdata);
+ MapState* state = (MapState*)(userdata);
state->status = status;
state->done = true;
};
@@ -238,7 +238,7 @@ std::vector<uint8_t> texture_readback_fp16_to_u8(WGPUDevice device,
void* userdata, void* user2) {
(void)message;
(void)user2;
- MapState* state = static_cast<MapState*>(userdata);
+ MapState* state = (MapState*)(userdata);
state->status = status;
state->done = true;
};
@@ -259,14 +259,14 @@ std::vector<uint8_t> texture_readback_fp16_to_u8(WGPUDevice device,
}
// Convert FP16 to U8 ([-1,1] → [0,255])
- const uint16_t* mapped_data = static_cast<const uint16_t*>(
+ const uint16_t* mapped_data = (const uint16_t*)(
wgpuBufferGetConstMappedRange(staging, 0, buffer_size));
std::vector<uint8_t> pixels(width * height * 4);
if (mapped_data) {
for (int y = 0; y < height; ++y) {
- const uint16_t* src_row = reinterpret_cast<const uint16_t*>(
- reinterpret_cast<const uint8_t*>(mapped_data) +
+ const uint16_t* src_row = (const uint16_t*)(
+ (const uint8_t*)(mapped_data) +
y * aligned_bytes_per_row);
for (int x = 0; x < width; ++x) {
float r = fp16_to_float(src_row[x * 4 + 0]);
@@ -281,10 +281,10 @@ std::vector<uint8_t> texture_readback_fp16_to_u8(WGPUDevice device,
a = (a + 1.0f) * 0.5f;
int idx = (y * width + x) * 4;
- pixels[idx + 0] = static_cast<uint8_t>(b * 255.0f); // B
- pixels[idx + 1] = static_cast<uint8_t>(g * 255.0f); // G
- pixels[idx + 2] = static_cast<uint8_t>(r * 255.0f); // R
- pixels[idx + 3] = static_cast<uint8_t>(a * 255.0f); // A
+ pixels[idx + 0] = (uint8_t)(b * 255.0f); // B
+ pixels[idx + 1] = (uint8_t)(g * 255.0f); // G
+ pixels[idx + 2] = (uint8_t)(r * 255.0f); // R
+ pixels[idx + 3] = (uint8_t)(a * 255.0f); // A
}
}
}
diff --git a/src/gpu/uniform_helper.h b/src/gpu/uniform_helper.h
index 8556c98..b2f3406 100644
--- a/src/gpu/uniform_helper.h
+++ b/src/gpu/uniform_helper.h
@@ -1,12 +1,10 @@
// This file is part of the 64k demo project.
-// It provides a generic uniform buffer helper to reduce boilerplate.
-// Templated on uniform struct type for type safety and automatic sizing.
+// Generic uniform buffer helper.
#pragma once
#include "gpu/gpu.h"
-// Generic uniform buffer helper
// Usage:
// UniformBuffer<MyUniforms> uniforms_;
// uniforms_.init(device);
@@ -15,18 +13,15 @@ template <typename T> class UniformBuffer {
public:
UniformBuffer() = default;
- // Initialize the uniform buffer with the device
void init(WGPUDevice device) {
buffer_ = gpu_create_buffer(
device, sizeof(T), WGPUBufferUsage_Uniform | WGPUBufferUsage_CopyDst);
}
- // Update the uniform buffer with new data
void update(WGPUQueue queue, const T& data) {
wgpuQueueWriteBuffer(queue, buffer_.buffer, 0, &data, sizeof(T));
}
- // Get the underlying GpuBuffer (for bind group creation)
GpuBuffer& get() {
return buffer_;
}
diff --git a/src/tests/3d/test_3d_physics.cc b/src/tests/3d/test_3d_physics.cc
index 26b9bfa..7858f2f 100644
--- a/src/tests/3d/test_3d_physics.cc
+++ b/src/tests/3d/test_3d_physics.cc
@@ -9,7 +9,7 @@
#include "3d/renderer.h"
#include "3d/renderer_helpers.h"
#include "3d/scene.h"
-#include "gpu/shaders.h"
+#include "effects/shaders.h"
#include "gpu/texture_manager.h"
#include "platform/platform.h"
#include "procedural/generator.h"
diff --git a/src/tests/3d/test_3d_render.cc b/src/tests/3d/test_3d_render.cc
index 9398649..bd301bd 100644
--- a/src/tests/3d/test_3d_render.cc
+++ b/src/tests/3d/test_3d_render.cc
@@ -7,8 +7,8 @@
#include "3d/renderer.h"
#include "3d/renderer_helpers.h"
#include "3d/scene.h"
+#include "effects/shaders.h"
#include "generated/assets.h"
-#include "gpu/shaders.h"
#include "gpu/texture_manager.h"
#include "platform/platform.h"
#include "procedural/generator.h"
diff --git a/src/tests/3d/test_mesh.cc b/src/tests/3d/test_mesh.cc
index 2a13125..746cfb1 100644
--- a/src/tests/3d/test_mesh.cc
+++ b/src/tests/3d/test_mesh.cc
@@ -7,7 +7,7 @@
#include "3d/renderer.h"
#include "3d/renderer_helpers.h"
#include "3d/scene.h"
-#include "gpu/shaders.h"
+#include "effects/shaders.h"
#include "gpu/texture_manager.h"
#include "platform/platform.h"
#include "procedural/generator.h"
diff --git a/src/tests/assets/test_sequence.cc b/src/tests/assets/test_sequence.cc
index 445e44b..8de9eca 100644
--- a/src/tests/assets/test_sequence.cc
+++ b/src/tests/assets/test_sequence.cc
@@ -179,7 +179,7 @@ int main() {
return 0;
}
-#else // v2 port TODO
+#else // v2 port TODO
int main() {
printf("test_sequence: SKIPPED (needs v2 port)\n");
return 0;
diff --git a/src/tests/common/effect_test_helpers.cc b/src/tests/common/effect_test_helpers.cc
index d776609..2a40f60 100644
--- a/src/tests/common/effect_test_helpers.cc
+++ b/src/tests/common/effect_test_helpers.cc
@@ -45,9 +45,9 @@ bool all_pixels_match_color(const std::vector<uint8_t>& pixels, int width,
const uint8_t g = pixels[offset + 1];
const uint8_t r = pixels[offset + 2];
- const int diff_r = static_cast<int>(r) - static_cast<int>(target_r);
- const int diff_g = static_cast<int>(g) - static_cast<int>(target_g);
- const int diff_b = static_cast<int>(b) - static_cast<int>(target_b);
+ const int diff_r = (int)(r) - (int)(target_r);
+ const int diff_g = (int)(g) - (int)(target_g);
+ const int diff_b = (int)(b) - (int)(target_b);
if (diff_r * diff_r + diff_g * diff_g + diff_b * diff_b >
tolerance * tolerance) {
@@ -66,4 +66,3 @@ uint64_t hash_pixels(const std::vector<uint8_t>& pixels) {
}
return hash;
}
-
diff --git a/src/tests/common/offscreen_render_target.cc b/src/tests/common/offscreen_render_target.cc
index 33f0ae0..2b0a43b 100644
--- a/src/tests/common/offscreen_render_target.cc
+++ b/src/tests/common/offscreen_render_target.cc
@@ -20,7 +20,7 @@ OffscreenRenderTarget::OffscreenRenderTarget(WGPUInstance instance,
.usage = WGPUTextureUsage_RenderAttachment | WGPUTextureUsage_CopySrc |
WGPUTextureUsage_TextureBinding,
.dimension = WGPUTextureDimension_2D,
- .size = {static_cast<uint32_t>(width), static_cast<uint32_t>(height), 1},
+ .size = {(uint32_t)(width), (uint32_t)(height), 1},
.format = format,
.mipLevelCount = 1,
.sampleCount = 1,
@@ -44,7 +44,7 @@ OffscreenRenderTarget::~OffscreenRenderTarget() {
void OffscreenRenderTarget::map_callback(WGPUMapAsyncStatus status,
void* userdata) {
- MapState* state = static_cast<MapState*>(userdata);
+ MapState* state = (MapState*)(userdata);
state->status = status;
state->done = true;
}
diff --git a/src/tests/gpu/test_demo_effects.cc b/src/tests/gpu/test_demo_effects.cc
index cebf4a6..f193c76 100644
--- a/src/tests/gpu/test_demo_effects.cc
+++ b/src/tests/gpu/test_demo_effects.cc
@@ -37,42 +37,33 @@ static void test_effects() {
}
std::vector<std::pair<const char*, std::shared_ptr<Effect>>> effects = {
- {"PassthroughEffect",
- std::make_shared<PassthroughEffect>(
- fixture.ctx(), std::vector<std::string>{"source"},
- std::vector<std::string>{"sink"})},
- {"GaussianBlurEffect",
- std::make_shared<GaussianBlurEffect>(
- fixture.ctx(), std::vector<std::string>{"source"},
- std::vector<std::string>{"sink"})},
- {"PlaceholderEffect",
- std::make_shared<PlaceholderEffect>(
- fixture.ctx(), std::vector<std::string>{"source"},
- std::vector<std::string>{"sink"})},
- {"HeptagonEffect",
- std::make_shared<HeptagonEffect>(
- fixture.ctx(), std::vector<std::string>{"source"},
- std::vector<std::string>{"sink"})},
- {"ParticlesEffect",
- std::make_shared<ParticlesEffect>(
- fixture.ctx(), std::vector<std::string>{"source"},
- std::vector<std::string>{"sink"})},
- {"RotatingCubeEffect",
- std::make_shared<RotatingCubeEffect>(
- fixture.ctx(), std::vector<std::string>{"source"},
- std::vector<std::string>{"sink"})},
- {"Hybrid3DEffect",
- std::make_shared<Hybrid3DEffect>(
- fixture.ctx(), std::vector<std::string>{"source"},
- std::vector<std::string>{"sink"})},
- {"FlashEffect",
- std::make_shared<FlashEffect>(
- fixture.ctx(), std::vector<std::string>{"source"},
- std::vector<std::string>{"sink"})},
- {"PeakMeterEffect",
- std::make_shared<PeakMeterEffect>(
- fixture.ctx(), std::vector<std::string>{"source"},
- std::vector<std::string>{"sink"})},
+ {"Passthrough", std::make_shared<Passthrough>(
+ fixture.ctx(), std::vector<std::string>{"source"},
+ std::vector<std::string>{"sink"}, 0.0f, 1000.0f)},
+ {"GaussianBlur", std::make_shared<GaussianBlur>(
+ fixture.ctx(), std::vector<std::string>{"source"},
+ std::vector<std::string>{"sink"}, 0.0f, 1000.0f)},
+ {"Placeholder", std::make_shared<Placeholder>(
+ fixture.ctx(), std::vector<std::string>{"source"},
+ std::vector<std::string>{"sink"}, 0.0f, 1000.0f)},
+ {"Heptagon", std::make_shared<Heptagon>(
+ fixture.ctx(), std::vector<std::string>{"source"},
+ std::vector<std::string>{"sink"}, 0.0f, 1000.0f)},
+ {"Particles", std::make_shared<Particles>(
+ fixture.ctx(), std::vector<std::string>{"source"},
+ std::vector<std::string>{"sink"}, 0.0f, 1000.0f)},
+ {"RotatingCube", std::make_shared<RotatingCube>(
+ fixture.ctx(), std::vector<std::string>{"source"},
+ std::vector<std::string>{"sink"}, 0.0f, 1000.0f)},
+ {"Hybrid3D", std::make_shared<Hybrid3D>(
+ fixture.ctx(), std::vector<std::string>{"source"},
+ std::vector<std::string>{"sink"}, 0.0f, 1000.0f)},
+ {"Flash", std::make_shared<Flash>(fixture.ctx(),
+ std::vector<std::string>{"source"},
+ std::vector<std::string>{"sink"}, 0.0f, 1000.0f)},
+ {"PeakMeter", std::make_shared<PeakMeter>(
+ fixture.ctx(), std::vector<std::string>{"source"},
+ std::vector<std::string>{"sink"}, 0.0f, 1000.0f)},
};
int passed = 0;
diff --git a/src/tests/gpu/test_effect_base.cc b/src/tests/gpu/test_effect_base.cc
index 8b0e6b2..29d3348 100644
--- a/src/tests/gpu/test_effect_base.cc
+++ b/src/tests/gpu/test_effect_base.cc
@@ -80,14 +80,14 @@ static void test_effect_construction() {
return;
}
- // Create PassthroughEffect (simple effect)
- auto effect = std::make_shared<PassthroughEffect>(
+ // Create Passthrough (simple effect)
+ auto effect = std::make_shared<Passthrough>(
fixture.ctx(), std::vector<std::string>{"source"},
- std::vector<std::string>{"sink"});
+ std::vector<std::string>{"sink"}, 0.0f, 1000.0f);
assert(effect != nullptr && "Effect should be constructed");
- fprintf(stdout, " ✓ PassthroughEffect constructed\n");
+ fprintf(stdout, " ✓ Passthrough constructed\n");
}
// Test 4: Effect added to sequence DAG
@@ -102,11 +102,12 @@ static void test_effect_in_sequence() {
// Create minimal sequence with one effect
class TestSequence : public Sequence {
- public:
+ public:
TestSequence(const GpuContext& ctx, int w, int h) : Sequence(ctx, w, h) {
- auto effect = std::make_shared<PassthroughEffect>(
- ctx, std::vector<std::string>{"source"},
- std::vector<std::string>{"sink"});
+ auto effect =
+ std::make_shared<Passthrough>(ctx, std::vector<std::string>{"source"},
+ std::vector<std::string>{"sink"}, 0.0f,
+ 1000.0f);
effect_dag_.push_back({effect, {"source"}, {"sink"}, 0});
init_effect_nodes();
@@ -134,11 +135,12 @@ static void test_sequence_render() {
OffscreenRenderTarget target(fixture.instance(), fixture.device(), 256, 256);
class TestSequence : public Sequence {
- public:
+ public:
TestSequence(const GpuContext& ctx, int w, int h) : Sequence(ctx, w, h) {
- auto effect = std::make_shared<PassthroughEffect>(
- ctx, std::vector<std::string>{"source"},
- std::vector<std::string>{"sink"});
+ auto effect =
+ std::make_shared<Passthrough>(ctx, std::vector<std::string>{"source"},
+ std::vector<std::string>{"sink"}, 0.0f,
+ 1000.0f);
effect_dag_.push_back({effect, {"source"}, {"sink"}, 0});
init_effect_nodes();
@@ -154,8 +156,8 @@ static void test_sequence_render() {
seq->preprocess(0.0f, 0.0f, 0.0f, 0.0f);
// Create encoder and attempt render
- WGPUCommandEncoder encoder = wgpuDeviceCreateCommandEncoder(
- fixture.device(), nullptr);
+ WGPUCommandEncoder encoder =
+ wgpuDeviceCreateCommandEncoder(fixture.device(), nullptr);
seq->render_effects(encoder);
@@ -177,7 +179,7 @@ static void test_sequence_time_params() {
}
class TestSequence : public Sequence {
- public:
+ public:
TestSequence(const GpuContext& ctx, int w, int h) : Sequence(ctx, w, h) {
init_effect_nodes();
}
diff --git a/src/tests/gpu/test_noise_functions.cc b/src/tests/gpu/test_noise_functions.cc
index eddd88e..d96a982 100644
--- a/src/tests/gpu/test_noise_functions.cc
+++ b/src/tests/gpu/test_noise_functions.cc
@@ -1,9 +1,9 @@
// This file is part of the 64k demo project.
// It validates that the noise.wgsl functions are accessible and usable.
+#include "effects/shaders.h"
#include "generated/assets.h"
#include "gpu/shader_composer.h"
-#include "gpu/shaders.h"
#include <cassert>
#include <cstdio>
#include <cstring>
diff --git a/src/tests/gpu/test_sequence.cc b/src/tests/gpu/test_sequence.cc
index 337381a..8e27efb 100644
--- a/src/tests/gpu/test_sequence.cc
+++ b/src/tests/gpu/test_sequence.cc
@@ -1,8 +1,8 @@
// Test file for Sequence v2 system
// Phase 1: Foundation tests (NodeRegistry, Sequence base class)
-#include "gpu/sequence.h"
#include "gpu/effect.h"
+#include "gpu/sequence.h"
#include "tests/common/webgpu_test_fixture.h"
#include <cassert>
#include <cstdio>
@@ -11,8 +11,10 @@
class TestEffect : public Effect {
public:
TestEffect(const GpuContext& ctx, const std::vector<std::string>& inputs,
- const std::vector<std::string>& outputs)
- : Effect(ctx, inputs, outputs), render_called_(false) {
+ const std::vector<std::string>& outputs, float start_time = 0.0f,
+ float end_time = 1000.0f)
+ : Effect(ctx, inputs, outputs, start_time, end_time),
+ render_called_(false) {
}
void render(WGPUCommandEncoder encoder, const UniformsSequenceParams& params,
@@ -132,16 +134,15 @@ void test_sequence_v2_dag_execution() {
class TestSequence : public Sequence {
public:
TestSequence(const GpuContext& ctx)
- : Sequence(ctx, 1280, 720),
- effect1_(std::make_shared<TestEffect>(ctx, std::vector<std::string>{"source"},
- std::vector<std::string>{"temp"})),
- effect2_(std::make_shared<TestEffect>(ctx, std::vector<std::string>{"temp"},
- std::vector<std::string>{"sink"})) {
+ : Sequence(ctx, 1280, 720), effect1_(std::make_shared<TestEffect>(
+ ctx, std::vector<std::string>{"source"},
+ std::vector<std::string>{"temp"})),
+ effect2_(std::make_shared<TestEffect>(
+ ctx, std::vector<std::string>{"temp"},
+ std::vector<std::string>{"sink"})) {
// Build DAG (2 effects in sequence)
- effect_dag_.push_back(
- {effect1_, {"source"}, {"temp"}, 0});
- effect_dag_.push_back(
- {effect2_, {"temp"}, {"sink"}, 1});
+ effect_dag_.push_back({effect1_, {"source"}, {"temp"}, 0});
+ effect_dag_.push_back({effect2_, {"temp"}, {"sink"}, 1});
}
std::shared_ptr<TestEffect> effect1_;
diff --git a/src/tests/gpu/test_sequence_e2e.cc b/src/tests/gpu/test_sequence_e2e.cc
index 91a8da2..5d59e0d 100644
--- a/src/tests/gpu/test_sequence_e2e.cc
+++ b/src/tests/gpu/test_sequence_e2e.cc
@@ -1,12 +1,12 @@
// End-to-end test for Sequence v2 system
// Tests compiler output instantiation and execution
-#include "gpu/sequence.h"
-#include "gpu/effect.h"
#include "effects/gaussian_blur_effect.h"
#include "effects/heptagon_effect.h"
#include "effects/passthrough_effect.h"
-#include "gpu/shaders.h"
+#include "effects/shaders.h"
+#include "gpu/effect.h"
+#include "gpu/sequence.h"
#include "tests/common/webgpu_test_fixture.h"
#include <cassert>
#include <cstdio>
@@ -21,22 +21,18 @@ class SimpleTestSequence : public Sequence {
nodes_.declare_node("temp", NodeType::U8X4_NORM, width_, height_);
// Effect DAG construction (2 effects: source->temp->sink)
- effect_dag_.push_back({
- .effect = std::make_shared<PassthroughEffect>(ctx,
- std::vector<std::string>{"source"},
- std::vector<std::string>{"temp"}),
- .input_nodes = {"source"},
- .output_nodes = {"temp"},
- .execution_order = 0
- });
- effect_dag_.push_back({
- .effect = std::make_shared<PassthroughEffect>(ctx,
- std::vector<std::string>{"temp"},
- std::vector<std::string>{"sink"}),
- .input_nodes = {"temp"},
- .output_nodes = {"sink"},
- .execution_order = 1
- });
+ effect_dag_.push_back({.effect = std::make_shared<Passthrough>(
+ ctx, std::vector<std::string>{"source"},
+ std::vector<std::string>{"temp"}, 0.0f, 1000.0f),
+ .input_nodes = {"source"},
+ .output_nodes = {"temp"},
+ .execution_order = 0});
+ effect_dag_.push_back({.effect = std::make_shared<Passthrough>(
+ ctx, std::vector<std::string>{"temp"},
+ std::vector<std::string>{"sink"}, 0.0f, 1000.0f),
+ .input_nodes = {"temp"},
+ .output_nodes = {"sink"},
+ .execution_order = 1});
}
};
diff --git a/src/tests/gpu/test_shader_compilation.cc b/src/tests/gpu/test_shader_compilation.cc
index 3a7c2cf..2aff115 100644
--- a/src/tests/gpu/test_shader_compilation.cc
+++ b/src/tests/gpu/test_shader_compilation.cc
@@ -5,9 +5,9 @@
// - Missing binding declarations
// - Type mismatches
+#include "effects/shaders.h"
#include "generated/assets.h"
#include "gpu/shader_composer.h"
-#include "gpu/shaders.h"
#include "platform/platform.h"
#include <cassert>
#include <cstdio>
diff --git a/src/util/asset_manager.cc b/src/util/asset_manager.cc
index 0baa063..a606b46 100644
--- a/src/util/asset_manager.cc
+++ b/src/util/asset_manager.cc
@@ -112,7 +112,7 @@ const uint8_t* GetAsset(AssetId asset_id, size_t* out_size) {
CHECK_RETURN_END
// Write header
- uint32_t* header = reinterpret_cast<uint32_t*>(generated_data);
+ uint32_t* header = (uint32_t*)(generated_data);
header[0] = (uint32_t)width;
header[1] = (uint32_t)height;
@@ -155,7 +155,7 @@ TextureAsset GetTextureAsset(AssetId asset_id) {
return {0, 0, nullptr};
}
- const uint32_t* header = reinterpret_cast<const uint32_t*>(data);
+ const uint32_t* header = (const uint32_t*)(data);
return {(int)header[0], (int)header[1], data + 8};
}
@@ -167,13 +167,13 @@ MeshAsset GetMeshAsset(AssetId asset_id) {
}
const uint8_t* ptr = data;
- uint32_t num_vertices = *reinterpret_cast<const uint32_t*>(ptr);
+ uint32_t num_vertices = *(const uint32_t*)(ptr);
ptr += sizeof(uint32_t);
- const MeshVertex* vertices = reinterpret_cast<const MeshVertex*>(ptr);
+ const MeshVertex* vertices = (const MeshVertex*)(ptr);
ptr += num_vertices * sizeof(MeshVertex);
- uint32_t num_indices = *reinterpret_cast<const uint32_t*>(ptr);
+ uint32_t num_indices = *(const uint32_t*)(ptr);
ptr += sizeof(uint32_t);
- const uint32_t* indices = reinterpret_cast<const uint32_t*>(ptr);
+ const uint32_t* indices = (const uint32_t*)(ptr);
return {num_vertices, vertices, num_indices, indices};
}
diff --git a/src/util/fatal_error.h b/src/util/fatal_error.h
index 988ec1d..e1dda38 100644
--- a/src/util/fatal_error.h
+++ b/src/util/fatal_error.h
@@ -31,17 +31,17 @@
// ==============================================================================
// Early return if device is nullptr (headless mode stub)
-#define HEADLESS_RETURN_IF_NULL(device) \
- do { \
- if ((device) == nullptr) \
- return; \
+#define HEADLESS_RETURN_IF_NULL(device) \
+ do { \
+ if ((device) == nullptr) \
+ return; \
} while (0)
// Early return with value if device is nullptr (headless mode stub)
-#define HEADLESS_RETURN_VAL_IF_NULL(device, val) \
- do { \
- if ((device) == nullptr) \
- return (val); \
+#define HEADLESS_RETURN_VAL_IF_NULL(device, val) \
+ do { \
+ if ((device) == nullptr) \
+ return (val); \
} while (0)
#endif /* defined(STRIP_ALL) || defined(FINAL_STRIP) */