I get a strange error in my particle system. I set the size of my buffers dynamically and I can change the number of my particles like I want. I am playing with numbers like 30k, 40k and everything in between. The maximum is reached with 40800... then I get the error from the title in my output terminal.
This is the code:
Log::logInfo(m_Name, "Bind particle buffers...");
/// ssbo sizes
constexpr ptrdiff_t positionSSBOsize = sizeof(glm::vec4) * NUM_PARTICLES;
constexpr ptrdiff_t velocitySSBOsize = sizeof(glm::vec2) * NUM_PARTICLES;
constexpr ptrdiff_t forceSSBOsize = sizeof(glm::vec2) * NUM_PARTICLES;
constexpr ptrdiff_t densitySSBOsize = sizeof(float) * NUM_PARTICLES;
constexpr ptrdiff_t pressureSSBOsize = sizeof(float) * NUM_PARTICLES;
/// total size
constexpr ptrdiff_t packedBufferSize = positionSSBOsize + velocitySSBOsize + forceSSBOsize + densitySSBOsize + pressureSSBOsize;
/// ssbo offsets
constexpr ptrdiff_t positionSSBOoffset = 0;
constexpr ptrdiff_t velocitySSBOoffset = positionSSBOsize;
constexpr ptrdiff_t forceSSBOoffset = velocitySSBOoffset + velocitySSBOsize;
constexpr ptrdiff_t densitySSBOoffset = forceSSBOoffset + forceSSBOsize;
constexpr ptrdiff_t pressureSSBOoffset = densitySSBOoffset + densitySSBOsize;
/// set inital positions
this->initParticleSeeds(packedBufferSize, positionSSBOsize, m_PackedParticlesBufferHandle);
/// bind to inital positions data
this->bindBufferToVertexArrayObject(m_ParticlePositionVaoHandle, m_PackedParticlesBufferHandle, PARTICLE_SEEDS_NR);
/// bindings
//@TODO: Here we got a problem after increasing NUM_PARTICLES, the error that the MAX_SHADER_STORAGE_BUFFER_BINDINGS are reached, thats why INVALID_ERROR is thrown
Log::logInfo(m_Name, "Bind particle buffers: positions");
glBindBufferRange(GL_SHADER_STORAGE_BUFFER, SHADER_PART_POS_NR, m_PackedParticlesBufferHandle, positionSSBOoffset, positionSSBOsize); /// Particle Positions
Log::logInfo(m_Name, "Bind particle buffers: velocities");
glBindBufferRange(GL_SHADER_STORAGE_BUFFER, SHADER_PART_VEL_NR, m_PackedParticlesBufferHandle, velocitySSBOoffset, velocitySSBOsize); /// Particle Velocities
Log::logInfo(m_Name, "Bind particle buffers: force");
glBindBufferRange(GL_SHADER_STORAGE_BUFFER, SHADER_PART_FRC_NR, m_PackedParticlesBufferHandle, forceSSBOoffset, forceSSBOsize); /// Particle Force
Log::logInfo(m_Name, "Bind particle buffers: density");
glBindBufferRange(GL_SHADER_STORAGE_BUFFER, SHADER_PART_DNS_NR, m_PackedParticlesBufferHandle, densitySSBOoffset, densitySSBOsize); /// Particle Density
Log::logInfo(m_Name, "Bind particle buffers: pressure");
glBindBufferRange(GL_SHADER_STORAGE_BUFFER, SHADER_PART_PRS_NR, m_PackedParticlesBufferHandle, pressureSSBOoffset, pressureSSBOsize); /// Particle Pressure
Log::logInitSucc(m_Name, "particle buffers");
Like I said, everything works fine except that at 40801 particles the following error shows up in my log and some of my buffers are not loaded anymore:
[APPLICATION]:: Bind particle buffers...
[APPLICATION]:: Init particle seeds ...
[APPLICATION]:: Save data in buffer ...
[SOURCE_API]:: [TYPE_OTHER][131185] [SEVERITY_NOTIFICATION] Buffer detailed info: Buffer object 3 (bound to GL_SHADER_STORAGE_BUFFER, usage hint is GL_STATIC_DRAW) will use VIDEO memory as the source for buffer object operations.
[APPLICATION]:: Init particle seeds SUCCESS!
[APPLICATION]:: Bind vertex array object (VAO) to buffer ...
[APPLICATION]:: Init VAO SUCCESS!
[APPLICATION]:: Bind particle buffers: positions
[APPLICATION]:: Bind particle buffers: velocities
[SOURCE_API]:: [TYPE_ERROR][1281] [SEVERITY_HIGH] GL_INVALID_VALUE error generated. <start> does not meet minimum alignment requirements for shader storage buffers.
[APPLICATION]:: Bind particle buffers: force
[SOURCE_API]:: [TYPE_ERROR][1281] [SEVERITY_HIGH] GL_INVALID_VALUE error generated. <start> does not meet minimum alignment requirements for shader storage buffers.
[APPLICATION]:: Bind particle buffers: density
[APPLICATION]:: Bind particle buffers: pressure
[SOURCE_API]:: [TYPE_ERROR][1281] [SEVERITY_HIGH] GL_INVALID_VALUE error generated. <start> does not meet minimum alignment requirements for shader storage buffers.
It is not possible to address arbitrary offsets into a buffer with glBindBufferRange
. The offset has to be a multiple of the respective buffer offset alignment which depends on the buffer type used. This restriction is platform depended and is imposed by the underlying memory architecture on the GPU.
For SSBOs (as used here), the relevant alignment can be queried with the following code:
glGetIntegeri_v(GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT, &alignment);
More details can be found in the OpenGL 4.6 Spec, Section 6.7.1