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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# GPU Procedural Phase 4: Texture Composition
**Status:** ✅ Complete
## Implementation
Multi-input composite shaders with configurable sampler support.
### API
```cpp
enum class SamplerType {
LinearClamp, LinearRepeat, NearestClamp, NearestRepeat
};
void create_gpu_composite_texture(
const std::string& name,
const std::string& shader_func,
const char* shader_code,
const void* uniform_data,
size_t uniform_size,
int width, int height,
const std::vector<std::string>& input_names,
SamplerType sampler = SamplerType::LinearClamp);
```
### Shaders
**gen_blend.wgsl** - Blend two textures with lerp factor:
- Bindings: output (0), uniform (1), input_a (2), input_b (3), sampler (4)
- Uniform: `{u32 width, height; f32 blend_factor, _pad0}`
**gen_mask.wgsl** - Multiply textures (masking):
- Bindings: output (0), uniform (1), input_a (2), input_b (3), sampler (4)
- Uniform: `{u32 width, height}`
### Usage
```cpp
extern const char* gen_blend_compute_wgsl;
struct { uint32_t width, height; float blend_factor, _pad0; } uni = {256, 256, 0.5f, 0.0f};
tex_mgr.create_gpu_composite_texture(
"blended", "gen_blend", gen_blend_compute_wgsl,
&uni, sizeof(uni), 256, 256,
{"noise_a", "noise_b"},
SamplerType::LinearClamp);
```
### Features
- **Dynamic bind groups:** N input textures + 1 sampler
- **Lazy sampler creation:** Map-based cache, 4 preset types
- **Multi-stage composition:** Composite of composites supported
- **Guarded with `#if !defined(STRIP_GPU_COMPOSITE)`**
### Size Impact
- Code: ~460 lines added
- Compressed: ~830 bytes (2 shaders + dispatch logic)
### Tests
`test_gpu_composite.cc`:
- Blend two noise textures
- Mask noise with grid
- Multi-stage composite (composite of composites)
All 35 tests passing.
|