// 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 #include #include #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 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 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 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