diff options
Diffstat (limited to 'src/tests/gpu/test_demo_effects.cc')
| -rw-r--r-- | src/tests/gpu/test_demo_effects.cc | 216 |
1 files changed, 45 insertions, 171 deletions
diff --git a/src/tests/gpu/test_demo_effects.cc b/src/tests/gpu/test_demo_effects.cc index 2a4bdf4..f5cea85 100644 --- a/src/tests/gpu/test_demo_effects.cc +++ b/src/tests/gpu/test_demo_effects.cc @@ -1,71 +1,34 @@ // This file is part of the 64k demo project. -// It tests all demo effect classes for basic construction and initialization. -// Validates that every effect can be instantiated and initialized without -// crashes. +// It tests all v2 demo effect classes for basic construction. +// Validates that every v2 effect can be instantiated without crashes. // -// MAINTENANCE REQUIREMENT: When adding a new effect to demo_effects.h: -// 1. Add it to the appropriate test list (post_process_effects or -// scene_effects) +// MAINTENANCE REQUIREMENT: When adding a new v2 effect to demo_effects.h: +// 1. Add it to the test list below // 2. Run test to verify: ./build/test_demo_effects -// 3. If the effect requires Renderer3D, add it to requires_3d check in -// test_scene_effects() -#include "../common/effect_test_helpers.h" #include "../common/webgpu_test_fixture.h" #include "gpu/demo_effects.h" -// TODO: Re-enable CNN effects once ported to v2 -// #include "../../../cnn_v1/src/cnn_v1_effect.h" #include <cassert> #include <cstdio> -#include <cstring> #include <memory> #include <vector> -// Helper: Test effect construction and initialization -// Returns: 0=failed, 1=passed, 2=skipped (requires full 3D setup) -static int test_effect_smoke(const char* name, std::shared_ptr<Effect> effect, - MainSequence* main_seq, bool requires_3d = false) { +// Helper: Test v2 effect construction +static int test_effect_v2(const char* name, std::shared_ptr<EffectV2> effect) { fprintf(stdout, " Testing %s...\n", name); - // Check construction if (!effect) { fprintf(stderr, " ✗ Construction failed\n"); return 0; } - // Should not be initialized yet - if (effect->is_initialized) { - fprintf(stderr, - " ✗ Should not be initialized before Sequence::init()\n"); - return 0; - } - - // Add to sequence and initialize - auto seq = std::make_shared<Sequence>(); - seq->add_effect(effect, 0.0f, 10.0f, 0); - - // Some effects require full 3D pipeline setup (Renderer3D with shaders) - // These will fail in init_test() environment - skip them gracefully - if (requires_3d) { - fprintf(stdout, " ⚠ Skipped (requires full 3D pipeline setup)\n"); - return 2; // Skipped - } - - seq->init(main_seq); - - // Should be initialized now - if (!effect->is_initialized) { - fprintf(stderr, " ✗ Should be initialized after Sequence::init()\n"); - return 0; - } - - fprintf(stdout, " ✓ %s construction and initialization OK\n", name); - return 1; // Passed + fprintf(stdout, " ✓ %s OK\n", name); + return 1; } -// Test 1: Post-process effects -static void test_post_process_effects() { - fprintf(stdout, "Testing post-process effects...\n"); +// Test all available v2 effects +static void test_v2_effects() { + fprintf(stdout, "Testing V2 effects...\n"); WebGPUTestFixture fixture; if (!fixture.init()) { @@ -73,130 +36,43 @@ static void test_post_process_effects() { return; } - MainSequence main_seq; - main_seq.init_test(fixture.ctx()); - - // Test each post-process effect - std::vector<std::pair<const char*, std::shared_ptr<Effect>>> effects = { - {"FlashEffect", std::make_shared<FlashEffect>(fixture.ctx())}, - {"PassthroughEffect", std::make_shared<PassthroughEffect>(fixture.ctx())}, - {"GaussianBlurEffect", - std::make_shared<GaussianBlurEffect>(fixture.ctx())}, - {"ChromaAberrationEffect", - std::make_shared<ChromaAberrationEffect>(fixture.ctx())}, - {"SolarizeEffect", std::make_shared<SolarizeEffect>(fixture.ctx())}, - {"FadeEffect", std::make_shared<FadeEffect>(fixture.ctx())}, - {"ThemeModulationEffect", - std::make_shared<ThemeModulationEffect>(fixture.ctx())}, - {"VignetteEffect", std::make_shared<VignetteEffect>(fixture.ctx())}, - {"CNNv1Effect", std::make_shared<CNNv1Effect>(fixture.ctx())}, - {"CNNv2Effect", std::make_shared<CNNv2Effect>(fixture.ctx())}, + std::vector<std::pair<const char*, std::shared_ptr<EffectV2>>> effects = { + {"PassthroughEffectV2", + std::make_shared<PassthroughEffectV2>( + fixture.ctx(), std::vector<std::string>{"source"}, + std::vector<std::string>{"sink"})}, + {"GaussianBlurEffectV2", + std::make_shared<GaussianBlurEffectV2>( + fixture.ctx(), std::vector<std::string>{"source"}, + std::vector<std::string>{"sink"})}, + {"PlaceholderEffectV2", + std::make_shared<PlaceholderEffectV2>( + fixture.ctx(), std::vector<std::string>{}, + std::vector<std::string>{"sink"})}, + {"HeptagonEffectV2", + std::make_shared<HeptagonEffectV2>( + fixture.ctx(), std::vector<std::string>{}, + std::vector<std::string>{"sink"})}, + {"ParticlesEffectV2", + std::make_shared<ParticlesEffectV2>( + fixture.ctx(), std::vector<std::string>{}, + std::vector<std::string>{"sink"})}, + {"RotatingCubeEffectV2", + std::make_shared<RotatingCubeEffectV2>( + fixture.ctx(), std::vector<std::string>{}, + std::vector<std::string>{"sink"})}, + {"Hybrid3DEffectV2", + std::make_shared<Hybrid3DEffectV2>( + fixture.ctx(), std::vector<std::string>{"source"}, + std::vector<std::string>{"sink"})}, }; int passed = 0; for (const auto& [name, effect] : effects) { - // Verify it's marked as post-process - assert(effect->is_post_process() && - "Post-process effect should return true for is_post_process()"); - - const int result = test_effect_smoke(name, effect, &main_seq, false); - if (result == 1) { - ++passed; - } + passed += test_effect_v2(name, effect); } - fprintf(stdout, " ✓ %d/%zu post-process effects tested\n", passed, - effects.size()); -} - -// Test 2: Scene effects -static void test_scene_effects() { - fprintf(stdout, "Testing scene effects...\n"); - - WebGPUTestFixture fixture; - if (!fixture.init()) { - fprintf(stdout, " ⚠ WebGPU unavailable - skipping test\n"); - return; - } - - MainSequence main_seq; - main_seq.init_test(fixture.ctx()); - - // Test each scene effect - std::vector<std::pair<const char*, std::shared_ptr<Effect>>> effects = { - {"HeptagonEffect", std::make_shared<HeptagonEffect>(fixture.ctx())}, - {"ParticlesEffect", std::make_shared<ParticlesEffect>(fixture.ctx())}, - {"ParticleSprayEffect", - std::make_shared<ParticleSprayEffect>(fixture.ctx())}, - {"MovingEllipseEffect", - std::make_shared<MovingEllipseEffect>(fixture.ctx())}, - {"FlashCubeEffect", std::make_shared<FlashCubeEffect>(fixture.ctx())}, - {"Hybrid3DEffect", std::make_shared<Hybrid3DEffect>(fixture.ctx())}, - {"CircleMaskEffect", std::make_shared<CircleMaskEffect>(fixture.ctx())}, - {"RotatingCubeEffect", - std::make_shared<RotatingCubeEffect>(fixture.ctx())}, - {"Scene1Effect", std::make_shared<Scene1Effect>(fixture.ctx())}, - {"SDFTestEffect", std::make_shared<SDFTestEffect>(fixture.ctx())}, - }; - - int passed = 0; - int skipped = 0; - for (const auto& [name, effect] : effects) { - // Scene effects should NOT be marked as post-process - assert(!effect->is_post_process() && - "Scene effect should return false for is_post_process()"); - - // FlashCubeEffect, Hybrid3DEffect, RotatingCubeEffect, and CircleMaskEffect - // require full 3D pipeline (Renderer3D) or auxiliary textures - const bool requires_3d = (strcmp(name, "FlashCubeEffect") == 0 || - strcmp(name, "Hybrid3DEffect") == 0 || - strcmp(name, "RotatingCubeEffect") == 0 || - strcmp(name, "CircleMaskEffect") == 0); - - const int result = test_effect_smoke(name, effect, &main_seq, requires_3d); - if (result == 1) { - ++passed; - } else if (result == 2) { - ++skipped; - } - } - - fprintf(stdout, " ✓ %d/%zu scene effects tested (%d skipped)\n", passed, - effects.size(), skipped); -} - -// Test 3: Effect type classification -static void test_effect_type_classification() { - fprintf(stdout, "Testing effect type classification...\n"); - - WebGPUTestFixture fixture; - if (!fixture.init()) { - fprintf(stdout, " ⚠ WebGPU unavailable - skipping test\n"); - return; - } - - // Post-process effects should return true - auto flash = std::make_shared<FlashEffect>(fixture.ctx()); - assert(flash->is_post_process() && "FlashEffect should be post-process"); - - auto blur = std::make_shared<GaussianBlurEffect>(fixture.ctx()); - assert(blur->is_post_process() && - "GaussianBlurEffect should be post-process"); - - auto vignette = std::make_shared<VignetteEffect>(fixture.ctx()); - assert(vignette->is_post_process() && - "VignetteEffect should be post-process"); - - // Scene effects should return false - auto heptagon = std::make_shared<HeptagonEffect>(fixture.ctx()); - assert(!heptagon->is_post_process() && - "HeptagonEffect should NOT be post-process"); - - auto particles = std::make_shared<ParticlesEffect>(fixture.ctx()); - assert(!particles->is_post_process() && - "ParticlesEffect should NOT be post-process"); - - fprintf(stdout, " ✓ Effect type classification correct\n"); + fprintf(stdout, " ✓ %d/%zu V2 effects tested\n", passed, effects.size()); } int main() { @@ -205,10 +81,8 @@ int main() { extern void InitShaderComposer(); InitShaderComposer(); - test_post_process_effects(); - test_scene_effects(); - test_effect_type_classification(); + test_v2_effects(); - fprintf(stdout, "=== All Demo Effects Tests Passed ===\n"); + fprintf(stdout, "=== All Tests Passed ===\n"); return 0; -}
\ No newline at end of file +} |
