diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-09 14:28:46 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-09 14:28:46 +0100 |
| commit | 9bb5fd64776ac8a7e4b012ac2de340ddfa09a2c9 (patch) | |
| tree | 79b99e6196ca70df8ddf3b9b0809ea5770ee0280 /src/tests/test_gpu_composite.cc | |
| parent | 8d6f14793a1edc34644297e2b24248c00bbff3be (diff) | |
feat: GPU procedural Phase 4 - texture composition
Multi-input composite shaders with sampler support.
- Dynamic bind group layouts (N input textures + 1 sampler)
- dispatch_composite() for multi-input compute dispatch
- create_gpu_composite_texture() API
- gen_blend.wgsl and gen_mask.wgsl shaders
Guarded with #if !defined(STRIP_GPU_COMPOSITE) for easy removal.
Tests:
- Blend two noise textures
- Mask noise with grid
- Multi-stage composite (composite of composites)
Size: ~830 bytes (2 shaders + dispatch logic)
handoff(Claude): GPU procedural Phase 4 complete
Diffstat (limited to 'src/tests/test_gpu_composite.cc')
| -rw-r--r-- | src/tests/test_gpu_composite.cc | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/src/tests/test_gpu_composite.cc b/src/tests/test_gpu_composite.cc new file mode 100644 index 0000000..e5ac788 --- /dev/null +++ b/src/tests/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 |
