Skip to content

Commit

Permalink
Reverting back to volume textures in pressure solver
Browse files Browse the repository at this point in the history
  • Loading branch information
Wumpf committed Oct 18, 2020
1 parent 6bf3d2f commit 5c9ccb3
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 30 deletions.
4 changes: 2 additions & 2 deletions shader/fluid_render_info.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ layout(set = 1, binding = 4) uniform texture3D VelocityVolumeX;
layout(set = 1, binding = 5) uniform texture3D VelocityVolumeY;
layout(set = 1, binding = 6) uniform texture3D VelocityVolumeZ;
layout(set = 1, binding = 7) uniform texture3D MarkerVolume;
layout(set = 1, binding = 8) uniform texture2DArray PressureVolume_Velocity;
layout(set = 1, binding = 9) uniform texture2DArray PressureVolume_Density;
layout(set = 1, binding = 8) uniform texture3D PressureVolume_Velocity;
layout(set = 1, binding = 9) uniform texture3D PressureVolume_Density;

ivec3 getVolumeCoordinate(uint positionIndex) {
ivec3 volumeSize = textureSize(PressureVolume_Velocity, 0).xyz;
Expand Down
2 changes: 1 addition & 1 deletion shader/simulation/bindings_write_volume.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ layout(set = 2, binding = 0) uniform texture3D MarkerVolume;
layout(set = 2, binding = 1, r32f) uniform restrict image3D VelocityVolumeX;
layout(set = 2, binding = 2, r32f) uniform restrict image3D VelocityVolumeY;
layout(set = 2, binding = 3, r32f) uniform restrict image3D VelocityVolumeZ;
layout(set = 2, binding = 4) uniform texture2DArray PressureVolume;
layout(set = 2, binding = 4) uniform texture3D PressureVolume;
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

layout(set = 2, binding = 0) buffer restrict ParticlePositionLlBuffer { ParticlePositionLl Particles[]; };
layout(set = 2, binding = 1) uniform texture3D MarkerVolume;
layout(set = 2, binding = 2) uniform texture2DArray PressureFromDensity;
layout(set = 2, binding = 2) uniform texture3D PressureFromDensity;

COMPUTE_PASS_PARTICLES

Expand Down
2 changes: 1 addition & 1 deletion shader/simulation/density_projection_gather_error.comp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
layout(set = 2, binding = 0) buffer restrict readonly ParticlePositionLlBuffer { ParticlePositionLl Particles[]; };
layout(set = 2, binding = 1) uniform utexture3D LinkedListDualGrid;
layout(set = 2, binding = 2, r8_snorm) uniform restrict image3D MarkerVolume;
layout(set = 2, binding = 3, r32f) uniform restrict image2DArray DensityVolume;
layout(set = 2, binding = 3, r32f) uniform restrict image3D DensityVolume;
// layout(push_constant) uniform PushConstants { uint VelocityTransferComponent; };

// Uses a shared memory so every thread loads one particle for its current cell and then accesses remaining neighbors (a 2x2x2 environment) from
Expand Down
2 changes: 1 addition & 1 deletion shader/simulation/divergence_compute.comp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ layout(set = 1, binding = 0) uniform texture3D MarkerVolume;
layout(set = 1, binding = 1) uniform texture3D VelocityVolumeX;
layout(set = 1, binding = 2) uniform texture3D VelocityVolumeY;
layout(set = 1, binding = 3) uniform texture3D VelocityVolumeZ;
layout(set = 1, binding = 4, r32f) uniform restrict image2DArray Divergence;
layout(set = 1, binding = 4, r32f) uniform restrict image3D Divergence;

COMPUTE_PASS_VOLUME

Expand Down
4 changes: 2 additions & 2 deletions shader/simulation/pressure_solver/pressure.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#define REDUCE_READS_PER_THREAD 16

layout(set = 0, binding = 0) uniform texture3D MarkerVolume;
layout(set = 1, binding = 0, r32f) uniform restrict image2DArray Pressure;
layout(set = 1, binding = 0, r32f) uniform restrict image3D Pressure;
layout(set = 1, binding = 1) uniform Config {
float TargetMSE;
uint MaxNumSolverIterations;
Expand All @@ -31,7 +31,7 @@ PushConstants;

// Result of multiplication with coefficient matrix with a texture at gridCoord.
// Only call if gridCoord is a fluid position!
float MultiplyWithCoefficientMatrix(ivec3 gridCoord, texture2DArray texture, float valueAtGridCoord) {
float MultiplyWithCoefficientMatrix(ivec3 gridCoord, texture3D texture, float valueAtGridCoord) {
float result = 0.0;
float markerX0 = texelFetch(MarkerVolume, gridCoord - ivec3(1, 0, 0), 0).x;
float markerX1 = texelFetch(MarkerVolume, gridCoord + ivec3(1, 0, 0), 0).x;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "pressure.glsl"

layout(set = 2, binding = 0) buffer restrict _ReduceBuffer { float ReduceBuffer[]; };
layout(set = 2, binding = 1) uniform texture2DArray Search;
layout(set = 2, binding = 1) uniform texture3D Search;

COMPUTE_PASS_PRESSURE

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
#include "pressure.glsl"

layout(set = 2, binding = 0) buffer restrict _ReduceBuffer { float ReduceBuffer[]; };
layout(set = 2, binding = 1) uniform texture2DArray Residual;
layout(set = 2, binding = 1) uniform texture3D Residual;

layout(set = 2, binding = 2, r32f) uniform restrict writeonly image2DArray AuxiliaryOrTemp;
layout(set = 2, binding = 3) uniform texture2DArray ResidualOrTemp;
layout(set = 2, binding = 2, r32f) uniform restrict writeonly image3D AuxiliaryOrTemp;
layout(set = 2, binding = 3) uniform texture3D ResidualOrTemp;

COMPUTE_PASS_PRESSURE

Expand Down
2 changes: 1 addition & 1 deletion shader/simulation/pressure_solver/pressure_init.comp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "pressure.glsl"

layout(set = 2, binding = 0, r32f) uniform restrict image2DArray Residual;
layout(set = 2, binding = 0, r32f) uniform restrict image3D Residual;
layout(set = 2, binding = 1) buffer restrict ReduceResultAndMainDispatchBuffer {
vec2 DotProductReduceResult;
float MSE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include "pressure.glsl"

layout(set = 2, binding = 0) buffer restrict _ReduceBuffer { float ReduceBuffer[]; };
layout(set = 2, binding = 1, r32f) uniform restrict image2DArray Residual;
layout(set = 2, binding = 2) uniform texture2DArray Search;
layout(set = 2, binding = 1, r32f) uniform restrict image3D Residual;
layout(set = 2, binding = 2) uniform texture3D Search;
layout(set = 2, binding = 3) uniform PcgScalars_ { PcgScalars Scalars; };

#define PRUPDATE_COMPUTE_MSE 1
Expand Down
4 changes: 2 additions & 2 deletions shader/simulation/pressure_solver/pressure_update_search.comp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

#include "pressure.glsl"

layout(set = 2, binding = 1, r32f) uniform restrict image2DArray Search;
layout(set = 2, binding = 2) uniform texture2DArray Auxillary;
layout(set = 2, binding = 1, r32f) uniform restrict image3D Search;
layout(set = 2, binding = 2) uniform texture3D Auxillary;
layout(set = 2, binding = 3) uniform PcgScalars_ { PcgScalars Scalars; };

COMPUTE_PASS_PRESSURE
Expand Down
8 changes: 4 additions & 4 deletions src/simulation/hybrid_fluid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,14 @@ impl HybridFluid {
.next_binding_compute(binding_glsl::texture3D()) // velocityX
.next_binding_compute(binding_glsl::texture3D()) // velocityY
.next_binding_compute(binding_glsl::texture3D()) // velocityZ
.next_binding_compute(binding_glsl::image2DArray(wgpu::TextureFormat::R32Float, false)) // divergence / initial residual
.next_binding_compute(binding_glsl::image3D(wgpu::TextureFormat::R32Float, false)) // divergence / initial residual
.create(device, "BindGroupLayout: Compute Divergence");
let group_layout_write_velocity_volume = BindGroupLayoutBuilder::new()
.next_binding_compute(binding_glsl::texture3D()) // marker volume
.next_binding_compute(binding_glsl::image3D(wgpu::TextureFormat::R32Float, false)) // velocityX
.next_binding_compute(binding_glsl::image3D(wgpu::TextureFormat::R32Float, false)) // velocityY
.next_binding_compute(binding_glsl::image3D(wgpu::TextureFormat::R32Float, false)) // velocityZ
.next_binding_compute(binding_glsl::texture2DArray()) // pressure
.next_binding_compute(binding_glsl::texture3D()) // pressure
.create(device, "BindGroupLayout: Write to Velocity");
let group_layout_advect_particles = BindGroupLayoutBuilder::new()
.next_binding_compute(binding_glsl::texture2D()) // velocityX
Expand All @@ -186,12 +186,12 @@ impl HybridFluid {
.next_binding_compute(binding_glsl::buffer(false)) // particles, position llindex
.next_binding_compute(binding_glsl::utexture3D()) // linkedlist_volume
.next_binding_compute(binding_glsl::image3D(wgpu::TextureFormat::R8Snorm, false)) // marker volume
.next_binding_compute(binding_glsl::image2DArray(wgpu::TextureFormat::R32Float, false)) // density volume
.next_binding_compute(binding_glsl::image3D(wgpu::TextureFormat::R32Float, false)) // density volume
.create(device, "BindGroupLayout: Compute density error");
let group_layout_density_projection_correct_particles = BindGroupLayoutBuilder::new()
.next_binding_compute(binding_glsl::buffer(false)) // particles, position llindex
.next_binding_compute(binding_glsl::texture3D()) // marker volume
.next_binding_compute(binding_glsl::texture2DArray()) // pressure from density
.next_binding_compute(binding_glsl::texture3D()) // pressure from density
.create(device, "BindGroupLayout: Correct density error");

let pressure_solver = PressureSolver::new(device, grid_dimension, shader_dir, pipeline_manager, &volume_marker_view);
Expand Down
18 changes: 9 additions & 9 deletions src/simulation/pressure_solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn create_volume_texture_desc(label: &str, grid_dimension: wgpu::Extent3d, forma
size: grid_dimension,
mip_level_count: 1,
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
dimension: wgpu::TextureDimension::D3,
format,
usage: wgpu::TextureUsage::SAMPLED | wgpu::TextureUsage::STORAGE,
}
Expand Down Expand Up @@ -233,31 +233,31 @@ impl PressureSolver {
.next_binding_compute(binding_glsl::texture3D())
.create(device, "BindGroupLayout: Pressure solver general");
let group_layout_pressure_field = BindGroupLayoutBuilder::new()
.next_binding_compute(binding_glsl::image2DArray(wgpu::TextureFormat::R32Float, false))
.next_binding_compute(binding_glsl::image3D(wgpu::TextureFormat::R32Float, false))
.next_binding_compute(binding_glsl::uniform())
.create(device, "BindGroupLayout: Pressure solver Pressure");
let group_layout_init = BindGroupLayoutBuilder::new()
.next_binding_compute(binding_glsl::image2DArray(wgpu::TextureFormat::R32Float, false))
.next_binding_compute(binding_glsl::image3D(wgpu::TextureFormat::R32Float, false))
.next_binding_compute(binding_glsl::buffer(false))
.create(device, "BindGroupLayout: Pressure solver init");
let group_layout_apply_coeff = BindGroupLayoutBuilder::new()
.next_binding_compute(binding_glsl::buffer(false))
.next_binding_compute(binding_glsl::texture2DArray())
.next_binding_compute(binding_glsl::texture3D())
.create(device, "BindGroupLayout: P. solver apply coeff matrix & start dot");
let group_layout_reduce = BindGroupLayoutBuilder::new()
.next_binding_compute(binding_glsl::buffer(true)) // source
.next_binding_compute(binding_glsl::buffer(false)) // dest
.create(device, "BindGroupLayout: Pressure solver dot product reduce");
let group_layout_preconditioner = BindGroupLayoutBuilder::new()
.next_binding_compute(binding_glsl::buffer(false))
.next_binding_compute(binding_glsl::texture2DArray())
.next_binding_compute(binding_glsl::image2DArray(wgpu::TextureFormat::R32Float, false))
.next_binding_compute(binding_glsl::texture2DArray())
.next_binding_compute(binding_glsl::texture3D())
.next_binding_compute(binding_glsl::image3D(wgpu::TextureFormat::R32Float, false))
.next_binding_compute(binding_glsl::texture3D())
.create(device, "BindGroupLayout: Pressure solver preconditioner");
let group_layout_update_volume = BindGroupLayoutBuilder::new()
.next_binding_compute(binding_glsl::buffer(false))
.next_binding_compute(binding_glsl::image2DArray(wgpu::TextureFormat::R32Float, false))
.next_binding_compute(binding_glsl::texture2DArray())
.next_binding_compute(binding_glsl::image3D(wgpu::TextureFormat::R32Float, false))
.next_binding_compute(binding_glsl::texture3D())
.next_binding_compute(binding_glsl::uniform())
.create(device, "BindGroupLayout: Pressure solver generic volume update");

Expand Down

0 comments on commit 5c9ccb3

Please sign in to comment.