diff options
Diffstat (limited to 'src/tests/gpu/test_gpu_procedural.cc')
| -rw-r--r-- | src/tests/gpu/test_gpu_procedural.cc | 117 |
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; +} |
