summaryrefslogtreecommitdiff
path: root/src/tests/gpu/test_gpu_procedural.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_procedural.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_procedural.cc')
-rw-r--r--src/tests/gpu/test_gpu_procedural.cc117
1 files changed, 117 insertions, 0 deletions
diff --git a/src/tests/gpu/test_gpu_procedural.cc b/src/tests/gpu/test_gpu_procedural.cc
new file mode 100644
index 0000000..f1bade0
--- /dev/null
+++ b/src/tests/gpu/test_gpu_procedural.cc
@@ -0,0 +1,117 @@
+// This file is part of the 64k demo project.
+// Tests GPU procedural texture generation.
+
+#include "gpu/gpu.h"
+#include "gpu/texture_manager.h"
+#include "platform/platform.h"
+#include <cstdio>
+
+int main() {
+ printf("GPU Procedural Test: Starting...\n");
+
+ // Minimal GPU initialization for testing
+ 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();
+
+ // Initialize shader composer (needed for #include resolution)
+ extern void InitShaderComposer();
+ InitShaderComposer();
+
+ // Create TextureManager
+ TextureManager tex_mgr;
+ tex_mgr.init(ctx->device, ctx->queue);
+
+ // Test GPU noise generation
+ GpuProceduralParams params = {};
+ params.width = 256;
+ params.height = 256;
+ float proc_params[2] = {0.0f, 4.0f}; // seed, frequency
+ params.params = proc_params;
+ params.num_params = 2;
+
+ tex_mgr.create_gpu_noise_texture("test_noise", params);
+
+ // Verify texture exists
+ WGPUTextureView view = tex_mgr.get_texture_view("test_noise");
+ if (!view) {
+ fprintf(stderr, "Error: GPU noise texture not created\n");
+ tex_mgr.shutdown();
+ gpu_shutdown();
+ return 1;
+ }
+ printf("SUCCESS: GPU noise texture created (256x256)\n");
+
+ // Test pipeline caching (create second noise texture)
+ tex_mgr.create_gpu_noise_texture("test_noise_2", params);
+ WGPUTextureView view2 = tex_mgr.get_texture_view("test_noise_2");
+ if (!view2) {
+ fprintf(stderr, "Error: Second GPU noise texture not created\n");
+ tex_mgr.shutdown();
+ gpu_shutdown();
+ return 1;
+ }
+ printf("SUCCESS: Pipeline caching works (second noise texture)\n");
+
+ // Test GPU perlin generation
+ float perlin_params[5] = {42.0f, 4.0f, 1.0f, 0.5f, 6.0f};
+ GpuProceduralParams perlin = {512, 256, perlin_params, 5};
+ tex_mgr.create_gpu_perlin_texture("test_perlin", perlin);
+ WGPUTextureView perlin_view = tex_mgr.get_texture_view("test_perlin");
+ if (!perlin_view) {
+ fprintf(stderr, "Error: GPU perlin texture not created\n");
+ tex_mgr.shutdown();
+ gpu_shutdown();
+ return 1;
+ }
+ printf("SUCCESS: GPU perlin texture created (512x256)\n");
+
+ // Test GPU grid generation
+ float grid_params[2] = {32.0f, 2.0f};
+ GpuProceduralParams grid = {256, 256, grid_params, 2};
+ tex_mgr.create_gpu_grid_texture("test_grid", grid);
+ WGPUTextureView grid_view = tex_mgr.get_texture_view("test_grid");
+ if (!grid_view) {
+ fprintf(stderr, "Error: GPU grid texture not created\n");
+ tex_mgr.shutdown();
+ gpu_shutdown();
+ return 1;
+ }
+ printf("SUCCESS: GPU grid texture created (256x256)\n");
+
+ // Test multiple pipelines coexist
+ printf("SUCCESS: All three GPU generators work (unified pipeline system)\n");
+
+ // Test variable-size textures
+ float noise_small[2] = {999.0f, 8.0f};
+ GpuProceduralParams small = {128, 64, noise_small, 2};
+ tex_mgr.create_gpu_noise_texture("noise_128x64", small);
+ if (!tex_mgr.get_texture_view("noise_128x64")) {
+ fprintf(stderr, "Error: Variable-size texture (128x64) not created\n");
+ tex_mgr.shutdown();
+ gpu_shutdown();
+ return 1;
+ }
+
+ float noise_large[2] = {777.0f, 2.0f};
+ GpuProceduralParams large = {1024, 512, noise_large, 2};
+ tex_mgr.create_gpu_noise_texture("noise_1024x512", large);
+ if (!tex_mgr.get_texture_view("noise_1024x512")) {
+ fprintf(stderr, "Error: Variable-size texture (1024x512) not created\n");
+ tex_mgr.shutdown();
+ gpu_shutdown();
+ return 1;
+ }
+ printf("SUCCESS: Variable-size textures work (128x64, 1024x512)\n");
+
+ // Cleanup
+ tex_mgr.shutdown();
+ gpu_shutdown();
+ platform_shutdown(&platform);
+ return 0;
+}