summaryrefslogtreecommitdiff
path: root/src/tests/gpu/test_gpu_composite.cc
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-09 20:27:04 +0100
committerskal <pascal.massimino@gmail.com>2026-02-09 20:27:04 +0100
commiteff8d43479e7704df65fae2a80eefa787213f502 (patch)
tree76f2fb8fe8d3db2c15179449df2cf12f7f54e0bf /src/tests/gpu/test_gpu_composite.cc
parent12378b1b7e9091ba59895b4360b2fa959180a56a (diff)
refactor: Reorganize tests into subsystem subdirectories
Restructured test suite for better organization and targeted testing: **Structure:** - src/tests/audio/ - 15 audio system tests - src/tests/gpu/ - 12 GPU/shader tests - src/tests/3d/ - 6 3D rendering tests - src/tests/assets/ - 2 asset system tests - src/tests/util/ - 3 utility tests - src/tests/common/ - 3 shared test helpers - src/tests/scripts/ - 2 bash test scripts (moved conceptually, not physically) **CMake changes:** - Updated add_demo_test macro to accept LABEL parameter - Applied CTest labels to all 36 tests for subsystem filtering - Updated all test file paths in CMakeLists.txt - Fixed common helper paths (webgpu_test_fixture, etc.) - Added custom targets for subsystem testing: - run_audio_tests, run_gpu_tests, run_3d_tests - run_assets_tests, run_util_tests, run_all_tests **Include path updates:** - Fixed relative includes in GPU tests to reference ../common/ **Documentation:** - Updated doc/HOWTO.md with subsystem test commands - Updated doc/CONTRIBUTING.md with new test organization - Updated scripts/check_all.sh to reflect new structure **Verification:** - All 36 tests passing (100%) - ctest -L <subsystem> filters work correctly - make run_<subsystem>_tests targets functional - scripts/check_all.sh passes Backward compatible: make test and ctest continue to work unchanged. handoff(Gemini): Test reorganization complete. 36/36 tests passing.
Diffstat (limited to 'src/tests/gpu/test_gpu_composite.cc')
-rw-r--r--src/tests/gpu/test_gpu_composite.cc124
1 files changed, 124 insertions, 0 deletions
diff --git a/src/tests/gpu/test_gpu_composite.cc b/src/tests/gpu/test_gpu_composite.cc
new file mode 100644
index 0000000..e5ac788
--- /dev/null
+++ b/src/tests/gpu/test_gpu_composite.cc
@@ -0,0 +1,124 @@
+// This file is part of the 64k demo project.
+// Tests GPU composite texture generation (Phase 4).
+
+#include "gpu/gpu.h"
+#include "gpu/texture_manager.h"
+#include "platform/platform.h"
+#include <cstdint>
+#include <cstdio>
+#include <vector>
+
+#if !defined(STRIP_GPU_COMPOSITE)
+
+int main() {
+ printf("GPU Composite Test: Starting...\n");
+
+ // Initialize GPU
+ PlatformState platform = platform_init(false, 256, 256);
+ if (!platform.window) {
+ fprintf(stderr, "Error: Failed to create window\n");
+ return 1;
+ }
+
+ gpu_init(&platform);
+ const GpuContext* ctx = gpu_get_context();
+
+ extern void InitShaderComposer();
+ InitShaderComposer();
+
+ TextureManager tex_mgr;
+ tex_mgr.init(ctx->device, ctx->queue);
+
+ // Create base textures
+ float noise_params_a[2] = {1234.0f, 4.0f};
+ GpuProceduralParams noise_a = {256, 256, noise_params_a, 2};
+ tex_mgr.create_gpu_noise_texture("noise_a", noise_a);
+
+ float noise_params_b[2] = {5678.0f, 8.0f};
+ GpuProceduralParams noise_b = {256, 256, noise_params_b, 2};
+ tex_mgr.create_gpu_noise_texture("noise_b", noise_b);
+
+ float grid_params[2] = {32.0f, 2.0f};
+ GpuProceduralParams grid = {256, 256, grid_params, 2};
+ tex_mgr.create_gpu_grid_texture("grid", grid);
+
+ printf("SUCCESS: Base textures created (noise_a, noise_b, grid)\n");
+
+ // Test blend composite
+ extern const char* gen_blend_compute_wgsl;
+ struct {
+ uint32_t width, height;
+ float blend_factor, _pad0;
+ } blend_uni = {256, 256, 0.5f, 0.0f};
+
+ std::vector<std::string> blend_inputs = {"noise_a", "noise_b"};
+ tex_mgr.create_gpu_composite_texture("blended", "gen_blend",
+ gen_blend_compute_wgsl, &blend_uni,
+ sizeof(blend_uni), 256, 256, blend_inputs);
+
+ WGPUTextureView blended_view = tex_mgr.get_texture_view("blended");
+ if (!blended_view) {
+ fprintf(stderr, "Error: Blended texture not created\n");
+ tex_mgr.shutdown();
+ gpu_shutdown();
+ return 1;
+ }
+ printf("SUCCESS: Blend composite created (noise_a + noise_b)\n");
+
+ // Test mask composite
+ extern const char* gen_mask_compute_wgsl;
+ struct {
+ uint32_t width, height;
+ } mask_uni = {256, 256};
+
+ std::vector<std::string> mask_inputs = {"noise_a", "grid"};
+ tex_mgr.create_gpu_composite_texture("masked", "gen_mask", gen_mask_compute_wgsl,
+ &mask_uni, sizeof(mask_uni), 256, 256,
+ mask_inputs);
+
+ WGPUTextureView masked_view = tex_mgr.get_texture_view("masked");
+ if (!masked_view) {
+ fprintf(stderr, "Error: Masked texture not created\n");
+ tex_mgr.shutdown();
+ gpu_shutdown();
+ return 1;
+ }
+ printf("SUCCESS: Mask composite created (noise_a * grid)\n");
+
+ // Test multi-stage composite (composite of composite)
+ struct {
+ uint32_t width, height;
+ float blend_factor, _pad0;
+ } blend2_uni = {256, 256, 0.7f, 0.0f};
+
+ std::vector<std::string> blend2_inputs = {"blended", "masked"};
+ tex_mgr.create_gpu_composite_texture("final", "gen_blend",
+ gen_blend_compute_wgsl, &blend2_uni,
+ sizeof(blend2_uni), 256, 256, blend2_inputs);
+
+ WGPUTextureView final_view = tex_mgr.get_texture_view("final");
+ if (!final_view) {
+ fprintf(stderr, "Error: Multi-stage composite not created\n");
+ tex_mgr.shutdown();
+ gpu_shutdown();
+ return 1;
+ }
+ printf("SUCCESS: Multi-stage composite (composite of composites)\n");
+
+ // Cleanup
+ tex_mgr.shutdown();
+ gpu_shutdown();
+ platform_shutdown(&platform);
+
+ printf("All GPU composite tests passed!\n");
+ return 0;
+}
+
+#else
+
+int main() {
+ printf("GPU Composite Test: SKIPPED (STRIP_GPU_COMPOSITE defined)\n");
+ return 0;
+}
+
+#endif