summaryrefslogtreecommitdiff
path: root/src/tests/test_gpu_procedural.cc
blob: f68eb4f26a3ae2801156048c8b35344f4237d02e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// 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");

  // Cleanup
  tex_mgr.shutdown();
  gpu_shutdown();
  platform_shutdown(&platform);
  return 0;
}