Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Windows 11 x64: download `PowderGame-<version>-win11-x64.zip` from the [latest r

### Requirements

You need a GPU and driver with OpenGL 4.3 core and enough shader resources: at least 18 image units and compute image uniforms, 19 combined shader output resources and 8 SSBO binding points. The app checks these at startup. The scene shader also uses 16 fragment texture units, the OpenGL 4.3 minimum. Building needs CMake 3.24 or newer, a C++20 compiler and Python (for the GLAD generator). CMake fetches pinned copies of GLFW and GLAD when no system copies are found.
You need a GPU and driver with OpenGL 4.3 core. Every shader stays within the limits OpenGL 4.3 guarantees (8 image units, 8 SSBO bindings, 16 texture units per stage), so it does not need the extra image units that AMD drivers offer and NVIDIA and Intel drivers usually do not. `gpu-compile` checks every shader against those limits. Building needs CMake 3.24 or newer, a C++20 compiler and Python (for the GLAD generator). CMake fetches pinned copies of GLFW and GLAD when no system copies are found.

### Build from source on Windows 11

Expand Down
28 changes: 28 additions & 0 deletions VALIDATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,34 @@ Replay fails if:
- combined scene has missing water/sand or inactive gas, violates source-free mass
conservation, or exceeds the configured GPU-time budget

## OpenGL 4.3 minimum resources - 2026-11-10 (on `b09f29f`)

v0.7.1 refused to start on GPUs that offer only the OpenGL 4.3 minimum of 8 image units (the usual
NVIDIA and Intel value): it required 18. Every shader now samples the fields it only reads
(`loadTexel`, `texelFetch` that returns zero outside the texture as `imageLoad` does) and keeps
image units for writes, numbered 0..7. The host's `BindImage` binds a read-only field to a texture
unit, a write-only one to an image unit and a read-write one to both, and every image barrier
also carries `GL_TEXTURE_FETCH_BARRIER_BIT`. The startup limit check is gone; `gpu-compile` now
fails any program over the 4.3 minimums (image uniforms on units 0..7, at most 8 images plus
storage blocks, storage bindings 0..7, at most 16 samplers).

Machine: Windows 11, AMD Radeon RX 7800 XT, `4.3.0 Core Profile Context 26.6.2.260602` (48 image
units, so the 8-unit limit itself was checked by `gpu-compile`, not by an NVIDIA or Intel run).
Binaries: `powder_game.exe` `f76bc22e5305`, `powder_gpu_tests.exe` `4ad2c9f0ff02`,
`powder_app_lifecycle_tests.exe` `042ad5d050a6`.

- `ctest -C Release -j 1`: 103/103 pass. `POWDER_REPLAY=all`: exit 0, all 12 scene runs pass.
- `benchmark-realtime`: PASS; idle GPU mean 1.70 ms, combined GPU mean/p95/max 18.52/25.21/30.19 ms.
- Replay signatures against `b09f29f` built from the same dependencies: water, sand, boundary
and leakage are bit-identical. Gas and combined differ (gas smoke 2803.48 to 3080.86) and both
pass. Bisected with every other shader restored: the difference comes from `smoke_correct` and
`gas_velocity_correct` alone, and no read there leaves its texture (an out-of-range sentinel
leaves the result unchanged) while a variant without the range check reproduces the old
signature exactly. The values read are the same; the fire scenes amplify the compiler's
different rounding.
- Replay frame avg ms, old/new: combined 12.34/12.79, gas 6.19/6.41, water 8.11/8.21 (single
runs each, other programs open).

## Current status - v0.7.0 integration, 2026-10-23 (committed as `12c1343`; measured on the pre-commit tree on `61e2965`)

This is the current result. The five pass sections that follow it are the work merged here, each measured in its own
Expand Down
6 changes: 2 additions & 4 deletions packaging/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ light over the simulation.
Notes:
- powder_game.exe is self-contained (shaders built in, C/C++ runtime linked
statically); run it from any folder.
- Requires OpenGL 4.3 core with at least 18 image units, 18 compute image
uniforms, 19 combined shader output resources, 8 SSBO bindings and 16
fragment texture units. The game checks the first four at startup and names
a missing one in a dialog.
- Requires an OpenGL 4.3 core GPU and driver; the
shaders stay within the limits OpenGL 4.3 guarantees.
- Source, documentation and measured limitations (VALIDATION.md):
https://github.com/FueledByRedBull/Powder-Game
16 changes: 12 additions & 4 deletions shaders/boundary_build.comp
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,29 @@

layout(local_size_x = 16, local_size_y = 16) in;

layout(r16ui, binding = 0) uniform readonly uimage2D materialTex;
layout(r16f, binding = 1) uniform readonly image2D sandOccupancyTex;
layout(binding = 0) uniform usampler2D materialTex;
layout(binding = 1) uniform sampler2D sandOccupancyTex;
layout(r8ui, binding = 2) uniform writeonly uimage2D boundaryTex;
layout(r8ui, binding = 3) uniform writeonly uimage2D staticBoundaryTex;

uniform ivec2 gridSize;

// Sampled reads keep imageLoad's result outside the texture: zero.
vec4 loadTexel(sampler2D t, ivec2 c) {
return all(lessThan(uvec2(c), uvec2(textureSize(t, 0)))) ? texelFetch(t, c, 0) : vec4(0.0);
}
uvec4 loadTexel(usampler2D t, ivec2 c) {
return all(lessThan(uvec2(c), uvec2(textureSize(t, 0)))) ? texelFetch(t, c, 0) : uvec4(0u);
}

void main() {
ivec2 coord = ivec2(gl_GlobalInvocationID.xy);
if (coord.x >= gridSize.x || coord.y >= gridSize.y) {
return;
}

uint material = imageLoad(materialTex, coord).r;
float sand_occupancy = imageLoad(sandOccupancyTex, coord).x;
uint material = loadTexel(materialTex, coord).r;
float sand_occupancy = loadTexel(sandOccupancyTex, coord).x;
// Painted rock (2) and wood (3, 256 and up while burning or charred; wood_burn.comp) are solids.
bool solid = material >= 2u;
uint static_blocked = solid ? 1u : 0u;
Expand Down
16 changes: 12 additions & 4 deletions shaders/boundary_distance.comp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@

layout(local_size_x = 16, local_size_y = 16) in;

layout(r8ui, binding = 0) uniform readonly uimage2D boundaryMaskTex;
layout(rg32i, binding = 1) uniform readonly iimage2D boundarySeedTex;
layout(binding = 0) uniform usampler2D boundaryMaskTex;
layout(binding = 1) uniform isampler2D boundarySeedTex;
layout(r16f, binding = 2) uniform writeonly image2D boundarySdfTex;

uniform ivec2 gridSize;
uniform float maxDistance;

// Sampled reads keep imageLoad's result outside the texture: zero.
uvec4 loadTexel(usampler2D t, ivec2 c) {
return all(lessThan(uvec2(c), uvec2(textureSize(t, 0)))) ? texelFetch(t, c, 0) : uvec4(0u);
}
ivec4 loadTexel(isampler2D t, ivec2 c) {
return all(lessThan(uvec2(c), uvec2(textureSize(t, 0)))) ? texelFetch(t, c, 0) : ivec4(0);
}

bool inBounds(ivec2 coord) {
return coord.x >= 0 && coord.y >= 0 && coord.x < gridSize.x && coord.y < gridSize.y;
}
Expand All @@ -19,8 +27,8 @@ void main() {
return;
}

bool inside = imageLoad(boundaryMaskTex, coord).r != 0u;
ivec2 seed = imageLoad(boundarySeedTex, coord).xy;
bool inside = loadTexel(boundaryMaskTex, coord).r != 0u;
ivec2 seed = loadTexel(boundarySeedTex, coord).xy;
float distance = maxDistance;
if (seed.x >= 0 && seed.y >= 0) {
// Interface seeds are cell centers on both sides; a half-cell offset preserves their signs.
Expand Down
18 changes: 13 additions & 5 deletions shaders/boundary_downsample.comp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

layout(local_size_x = 16, local_size_y = 16) in;

layout(r8ui, binding = 0) uniform readonly uimage2D srcBoundaryTex;
layout(binding = 0) uniform usampler2D srcBoundaryTex;
layout(r8ui, binding = 1) uniform writeonly uimage2D dstBoundaryTex;
layout(r16f, binding = 2) uniform readonly image2D liquidVolumeTex; // water plus oil volume per source cell
layout(rg16f, binding = 3) uniform readonly image2D oilTex; // x: oil share of that liquid (oil_field.comp)
layout(binding = 2) uniform sampler2D liquidVolumeTex; // water plus oil volume per source cell
layout(binding = 3) uniform sampler2D oilTex; // x: oil share of that liquid (oil_field.comp)

uniform ivec2 srcSize;
uniform ivec2 dstSize;
Expand All @@ -15,6 +15,14 @@ uniform int scale;
// Zero (unset) leaves water open.
uniform float waterBlockVolume;

// Sampled reads keep imageLoad's result outside the texture: zero.
vec4 loadTexel(sampler2D t, ivec2 c) {
return all(lessThan(uvec2(c), uvec2(textureSize(t, 0)))) ? texelFetch(t, c, 0) : vec4(0.0);
}
uvec4 loadTexel(usampler2D t, ivec2 c) {
return all(lessThan(uvec2(c), uvec2(textureSize(t, 0)))) ? texelFetch(t, c, 0) : uvec4(0u);
}

bool inBounds(ivec2 coord, ivec2 size) {
return coord.x >= 0 && coord.y >= 0 && coord.x < size.x && coord.y < size.y;
}
Expand All @@ -32,7 +40,7 @@ void main() {
uint blocked = 0u;
for (int y = src_min.y; y < src_max.y && blocked != 1u; ++y) {
for (int x = src_min.x; x < src_max.x; ++x) {
uint source = imageLoad(srcBoundaryTex, ivec2(x, y)).r;
uint source = loadTexel(srcBoundaryTex, ivec2(x, y)).r;
if (source == 1u) {
blocked = 1u;
break;
Expand All @@ -46,7 +54,7 @@ void main() {
bool submerged = true;
for (int i = 0; i < scale * scale && submerged; ++i) {
ivec2 cell = min(dst * scale + ivec2(i % scale, i / scale), srcSize - 1);
submerged = imageLoad(liquidVolumeTex, cell).x * (1.0 - imageLoad(oilTex, cell).x) >= waterBlockVolume;
submerged = loadTexel(liquidVolumeTex, cell).x * (1.0 - loadTexel(oilTex, cell).x) >= waterBlockVolume;
}
if (submerged) blocked = 3u;
}
Expand Down
11 changes: 8 additions & 3 deletions shaders/boundary_jumpflood.comp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

layout(local_size_x = 16, local_size_y = 16) in;

layout(rg32i, binding = 0) uniform readonly iimage2D srcSeedTex;
layout(binding = 0) uniform isampler2D srcSeedTex;
layout(rg32i, binding = 1) uniform writeonly iimage2D dstSeedTex;

uniform ivec2 gridSize;
uniform int stepSize;

// Sampled reads keep imageLoad's result outside the texture: zero.
ivec4 loadTexel(isampler2D t, ivec2 c) {
return all(lessThan(uvec2(c), uvec2(textureSize(t, 0)))) ? texelFetch(t, c, 0) : ivec4(0);
}

bool inBounds(ivec2 coord) {
return coord.x >= 0 && coord.y >= 0 && coord.x < gridSize.x && coord.y < gridSize.y;
}
Expand All @@ -27,7 +32,7 @@ void main() {
return;
}

ivec2 best_seed = imageLoad(srcSeedTex, coord).xy;
ivec2 best_seed = loadTexel(srcSeedTex, coord).xy;
float best_distance = validSeed(best_seed) ? seedDistanceSq(coord, best_seed) : 3.402823466e+38;

for (int y = -1; y <= 1; ++y) {
Expand All @@ -36,7 +41,7 @@ void main() {
if (!inBounds(sample_coord)) {
continue;
}
ivec2 candidate_seed = imageLoad(srcSeedTex, sample_coord).xy;
ivec2 candidate_seed = loadTexel(srcSeedTex, sample_coord).xy;
if (!validSeed(candidate_seed)) {
continue;
}
Expand Down
9 changes: 7 additions & 2 deletions shaders/boundary_mask.comp
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,24 @@

layout(local_size_x = 16, local_size_y = 16) in;

layout(r16f, binding = 0) uniform readonly image2D boundarySdfTex;
layout(binding = 0) uniform sampler2D boundarySdfTex;
layout(r8ui, binding = 1) uniform writeonly uimage2D boundaryMaskTex;

uniform ivec2 gridSize;
uniform float solidThreshold;

// Sampled reads keep imageLoad's result outside the texture: zero.
vec4 loadTexel(sampler2D t, ivec2 c) {
return all(lessThan(uvec2(c), uvec2(textureSize(t, 0)))) ? texelFetch(t, c, 0) : vec4(0.0);
}

void main() {
ivec2 coord = ivec2(gl_GlobalInvocationID.xy);
if (coord.x >= gridSize.x || coord.y >= gridSize.y) {
return;
}

float sdf = imageLoad(boundarySdfTex, coord).x;
float sdf = loadTexel(boundarySdfTex, coord).x;
uint blocked = sdf <= solidThreshold ? 1u : 0u;
imageStore(boundaryMaskTex, coord, uvec4(blocked, 0u, 0u, 0u));
}
9 changes: 7 additions & 2 deletions shaders/boundary_seed.comp
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@

layout(local_size_x = 16, local_size_y = 16) in;

layout(r8ui, binding = 0) uniform readonly uimage2D boundaryMaskTex;
layout(binding = 0) uniform usampler2D boundaryMaskTex;
layout(rg32i, binding = 1) uniform writeonly iimage2D boundarySeedTex;

uniform ivec2 gridSize;

// Sampled reads keep imageLoad's result outside the texture: zero.
uvec4 loadTexel(usampler2D t, ivec2 c) {
return all(lessThan(uvec2(c), uvec2(textureSize(t, 0)))) ? texelFetch(t, c, 0) : uvec4(0u);
}

bool inBounds(ivec2 coord) {
return coord.x >= 0 && coord.y >= 0 && coord.x < gridSize.x && coord.y < gridSize.y;
}

bool occupied(ivec2 coord) {
return inBounds(coord) && imageLoad(boundaryMaskTex, coord).r != 0u;
return inBounds(coord) && loadTexel(boundaryMaskTex, coord).r != 0u;
}

void main() {
Expand Down
24 changes: 16 additions & 8 deletions shaders/coupling_fire.comp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

layout(local_size_x = 16, local_size_y = 16) in;

layout(r8ui, binding = 0) uniform readonly uimage2D boundaryTex;
layout(r16f, binding = 1) uniform readonly image2D waterAmountTex;
layout(r16f, binding = 2) uniform readonly image2D temperatureTex;
layout(binding = 0) uniform usampler2D boundaryTex;
layout(binding = 1) uniform sampler2D waterAmountTex;
layout(binding = 2) uniform sampler2D temperatureTex;
layout(rg16f, binding = 3) uniform image2D combustionTex;
layout(r16f, binding = 4) uniform image2D oxidizerTex;
layout(r16f, binding = 5) uniform image2D fuelTex;
layout(rg16f, binding = 6) uniform readonly image2D oilTex; // x: oil share of the liquid (oil_field.comp)
layout(r16f, binding = 7) uniform readonly image2D sandOccupancyTex;
layout(binding = 6) uniform sampler2D oilTex; // x: oil share of the liquid (oil_field.comp)
layout(binding = 7) uniform sampler2D sandOccupancyTex;

uniform ivec2 gridSize;
uniform ivec2 heatSize;
Expand All @@ -18,15 +18,23 @@ uniform float waterCooling;
// Sand occupancy at which sand covering a cell smothers its fire completely (cuts fuel and oxygen like water does).
uniform float sandSmother;

// Sampled reads keep imageLoad's result outside the texture: zero.
vec4 loadTexel(sampler2D t, ivec2 c) {
return all(lessThan(uvec2(c), uvec2(textureSize(t, 0)))) ? texelFetch(t, c, 0) : vec4(0.0);
}
uvec4 loadTexel(usampler2D t, ivec2 c) {
return all(lessThan(uvec2(c), uvec2(textureSize(t, 0)))) ? texelFetch(t, c, 0) : uvec4(0u);
}

// Liquid that is water, not oil (oil is fuel, not a quencher), and sand, averaged over the gas cell's 2x2 cells.
float sampleWater(ivec2 gas_coord, out float sand) {
ivec2 full = clamp(gas_coord * 2, ivec2(0), gridSize - ivec2(2));
float water = 0.0;
sand = 0.0;
for (int i = 0; i < 4; ++i) {
ivec2 cell = full + ivec2(i & 1, i >> 1);
water += imageLoad(waterAmountTex, cell).x * (1.0 - imageLoad(oilTex, cell).x);
sand += imageLoad(sandOccupancyTex, cell).x;
water += loadTexel(waterAmountTex, cell).x * (1.0 - loadTexel(oilTex, cell).x);
sand += loadTexel(sandOccupancyTex, cell).x;
}
sand *= 0.25;
return 0.25 * water;
Expand All @@ -44,7 +52,7 @@ void main() {
float oxidizer = imageLoad(oxidizerTex, coord).x;
float fuel = imageLoad(fuelTex, coord).x;

if (imageLoad(boundaryTex, coord).r != 0u) {
if (loadTexel(boundaryTex, coord).r != 0u) {
imageStore(combustionTex, coord, vec4(0.0));
imageStore(oxidizerTex, coord, vec4(0.0));
imageStore(fuelTex, coord, vec4(0.0));
Expand Down
11 changes: 8 additions & 3 deletions shaders/coupling_heat.comp
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@
layout(local_size_x = 16, local_size_y = 16) in;

layout(r16f, binding = 0) uniform image2D temperatureTex;
layout(r16f, binding = 1) uniform readonly image2D waterAmountTex;
layout(rg16f, binding = 2) uniform readonly image2D oilTex; // x: oil share of the liquid; oil does not cool
layout(binding = 1) uniform sampler2D waterAmountTex;
layout(binding = 2) uniform sampler2D oilTex; // x: oil share of the liquid; oil does not cool

uniform ivec2 heatSize;
uniform ivec2 gridSize;
uniform float dt;
uniform float waterCooling;

// Sampled reads keep imageLoad's result outside the texture: zero.
vec4 loadTexel(sampler2D t, ivec2 c) {
return all(lessThan(uvec2(c), uvec2(textureSize(t, 0)))) ? texelFetch(t, c, 0) : vec4(0.0);
}

float waterSample(ivec2 full_coord) {
ivec2 clamped = clamp(full_coord, ivec2(0), gridSize - ivec2(1));
return imageLoad(waterAmountTex, clamped).x * (1.0 - imageLoad(oilTex, clamped).x);
return loadTexel(waterAmountTex, clamped).x * (1.0 - loadTexel(oilTex, clamped).x);
}

void main() {
Expand Down
Loading
Loading