Update ComputeBoids to use SSBOs as arrays

This is due to restrictions in HLSL. The size of RWStructuredBuffer<T> elements in Shader
Model 5.1 cannot be larger than 2048 bytes so we cannot use a
RWStructuredBuffer<Arr>, where Arr is a struct containing a large array.
This commit is contained in:
Austin Eng 2017-07-05 17:29:34 -04:00 committed by Austin Eng
parent fb19c3606b
commit dc6bb4a16c

View File

@ -155,12 +155,12 @@ void initSim() {
} params; } params;
layout(std140, set = 0, binding = 1) buffer ParticlesA { layout(std140, set = 0, binding = 1) buffer ParticlesA {
Particle particlesA[1000]; Particle particle;
}; } particlesA[1000];
layout(std140, set = 0, binding = 2) buffer ParticlesB { layout(std140, set = 0, binding = 2) buffer ParticlesB {
Particle particlesB[1000]; Particle particle;
}; } particlesB[1000];
void main() { void main() {
// https://github.com/austinEng/Project6-Vulkan-Flocking/blob/master/data/shaders/computeparticles/particle.comp // https://github.com/austinEng/Project6-Vulkan-Flocking/blob/master/data/shaders/computeparticles/particle.comp
@ -168,8 +168,8 @@ void initSim() {
uint index = gl_GlobalInvocationID.x; uint index = gl_GlobalInvocationID.x;
if (index >= params.particleCount) { return; } if (index >= params.particleCount) { return; }
vec2 vPos = particlesA[index].pos; vec2 vPos = particlesA[index].particle.pos;
vec2 vVel = particlesA[index].vel; vec2 vVel = particlesA[index].particle.vel;
vec2 cMass = vec2(0.0, 0.0); vec2 cMass = vec2(0.0, 0.0);
vec2 cVel = vec2(0.0, 0.0); vec2 cVel = vec2(0.0, 0.0);
@ -181,8 +181,8 @@ void initSim() {
vec2 vel; vec2 vel;
for (int i = 0; i < params.particleCount; ++i) { for (int i = 0; i < params.particleCount; ++i) {
if (i == index) { continue; } if (i == index) { continue; }
pos = particlesA[i].pos.xy; pos = particlesA[i].particle.pos.xy;
vel = particlesA[i].vel.xy; vel = particlesA[i].particle.vel.xy;
if (distance(pos, vPos) < params.rule1Distance) { if (distance(pos, vPos) < params.rule1Distance) {
cMass += pos; cMass += pos;
@ -217,10 +217,10 @@ void initSim() {
if (vPos.y < -1.0) vPos.y = 1.0; if (vPos.y < -1.0) vPos.y = 1.0;
if (vPos.y > 1.0) vPos.y = -1.0; if (vPos.y > 1.0) vPos.y = -1.0;
particlesB[index].pos = vPos; particlesB[index].particle.pos = vPos;
// Write back // Write back
particlesB[index].vel = vVel; particlesB[index].particle.vel = vVel;
} }
)"); )");