summaryrefslogtreecommitdiff
path: root/src/gpu/texture_manager.h
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-09 13:52:37 +0100
committerskal <pascal.massimino@gmail.com>2026-02-09 13:52:37 +0100
commitc712874ece1ca7073904f5fb84cc866d28084de0 (patch)
treef46727b58d3ac0e4ba3f36d50ea147c086282232 /src/gpu/texture_manager.h
parent0151a43cd179bd08584347e13327a3a722bddf2a (diff)
feat(gpu): Add GPU procedural texture generation system
Phase 1 implementation complete: - GPU compute shader for noise generation (gen_noise.wgsl) - TextureManager extensions: create_gpu_noise_texture(), dispatch_noise_compute() - Asset packer PROC_GPU() syntax support with validation - ShaderComposer integration for #include resolution - Zero CPU memory overhead (GPU-only textures) - Init-time and on-demand generation modes Technical details: - 8×8 workgroup size for 256×256 textures - UniformBuffer for params (width, height, seed, frequency) - Storage texture binding (rgba8unorm, write-only) - Lazy pipeline compilation on first use - ~300 bytes code (Phase 1) Testing: - New test: test_gpu_procedural.cc (passes) - All 34 tests passing (100%) Future phases: - Phase 2: Add gen_perlin, gen_grid compute shaders - Phase 3: Variable dimensions, async generation Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Diffstat (limited to 'src/gpu/texture_manager.h')
-rw-r--r--src/gpu/texture_manager.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/gpu/texture_manager.h b/src/gpu/texture_manager.h
index 23fdbe8..0cffe0c 100644
--- a/src/gpu/texture_manager.h
+++ b/src/gpu/texture_manager.h
@@ -23,6 +23,13 @@ struct GpuTexture {
int height;
};
+struct GpuProceduralParams {
+ int width;
+ int height;
+ const float* params;
+ int num_params;
+};
+
class TextureManager {
public:
void init(WGPUDevice device, WGPUQueue queue);
@@ -36,11 +43,24 @@ class TextureManager {
void create_texture(const std::string& name, int width, int height,
const uint8_t* data);
+ // GPU procedural generation
+ void create_gpu_noise_texture(const std::string& name,
+ const GpuProceduralParams& params);
+
+#if !defined(STRIP_ALL)
+ // On-demand lazy generation (stripped in final builds)
+ WGPUTextureView get_or_generate_gpu_texture(const std::string& name,
+ const GpuProceduralParams& params);
+#endif
+
// Retrieves a texture view by name (returns nullptr if not found)
WGPUTextureView get_texture_view(const std::string& name);
private:
+ void dispatch_noise_compute(WGPUTexture target,
+ const GpuProceduralParams& params);
WGPUDevice device_;
WGPUQueue queue_;
std::map<std::string, GpuTexture> textures_;
+ WGPUComputePipeline noise_compute_pipeline_ = nullptr;
};