{
DE_ASSERT(storage.data.empty() && storage.pointers.empty());
- const vector<int> bufferSizes = computeBufferSizes(interface, layout);
- int totalSize = 0;
+ const vector<int> bufferSizes = computeBufferSizes(interface, layout);
+ int totalSize = 0;
+ const int vec4Alignment = (int)sizeof(deUint32)*4;
for (vector<int>::const_iterator sizeIter = bufferSizes.begin(); sizeIter != bufferSizes.end(); ++sizeIter)
- totalSize += *sizeIter;
+ {
+ // Include enough space for alignment of individual blocks
+ totalSize += deRoundUp32(*sizeIter, vec4Alignment);
+ }
storage.data.resize(totalSize);
storage.pointers[blockNdx] = getBlockDataPtr(layout, blockLayout, basePtr + curOffset, bufferSize);
- curOffset += bufferSize;
+ // Ensure each new block starts fully aligned to avoid unaligned host accesses
+ curOffset += deRoundUp32(bufferSize, vec4Alignment);
}
}
}
void UniformBlockCase::init (void)
{
+ const int vec4Alignment = (int)sizeof(deUint32)*4;
+
// Compute reference layout.
computeStd140Layout(m_uniformLayout, m_interface);
{
int totalSize = 0;
for (std::vector<BlockLayoutEntry>::const_iterator blockIter = m_uniformLayout.blocks.begin(); blockIter != m_uniformLayout.blocks.end(); blockIter++)
- totalSize += blockIter->size;
+ {
+ // Include enough space for alignment of individual blocks
+ totalSize += deRoundUp32(blockIter->size, vec4Alignment);
+ }
m_data.resize(totalSize);
// Pointers for each block.
for (int blockNdx = 0; blockNdx < (int)m_uniformLayout.blocks.size(); blockNdx++)
{
m_blockPointers[blockNdx] = &m_data[0] + curOffset;
- curOffset += m_uniformLayout.blocks[blockNdx].size;
+
+ // Ensure each new block starts fully aligned to avoid unaligned host accesses
+ curOffset += deRoundUp32(m_uniformLayout.blocks[blockNdx].size, vec4Alignment);
}
}