我的粒子系统出现一个奇怪的错误。我可以动态设置缓冲区的大小,并且可以根据需要更改粒子的数量。我正在玩数字30k,40k及其之间的所有数字。 40800达到了最大值……然后我从输出终端的标题中得到了错误。
这是代码:
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");
就像我说的那样,一切正常,除了在40801粒子处,以下错误显示在我的日志中,并且某些缓冲区不再加载:
[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.
答案 0 :(得分:0)
不可能用glBindBufferRange
将任意偏移量寻址到缓冲区中。偏移量必须是相应缓冲区偏移量对齐的倍数,具体取决于所使用的缓冲区类型。此限制取决于平台,并且由GPU上的基础内存体系结构施加。
对于SSBO(此处使用),可以使用以下代码查询相关对齐方式:
glGetIntegeri_v(GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT, &alignment);
更多详细信息,请访问OpenGL 4.6 Spec, Section 6.7.1