parent
19245a0f51
commit
5107cf3ed0
2 changed files with 13 additions and 7 deletions
|
|
@ -48,9 +48,12 @@ First step is to calculate the alignment required for the data we want to store
|
|||
```cpp
|
||||
void prepareUniformBuffers()
|
||||
{
|
||||
// Calculate required alignment depending on device limits
|
||||
size_t uboAlignment = vulkanDevice->properties.limits.minUniformBufferOffsetAlignment;
|
||||
dynamicAlignment = (sizeof(glm::mat4) / uboAlignment) * uboAlignment + ((sizeof(glm::mat4) % uboAlignment) > 0 ? uboAlignment : 0);
|
||||
// Calculate required alignment based on minimum device offset alignment
|
||||
size_t minUboAlignment = vulkanDevice->properties.limits.minUniformBufferOffsetAlignment;
|
||||
dynamicAlignment = sizeof(glm::mat4);
|
||||
if (minUboAlignment > 0) {
|
||||
dynamicAlignment = (dynamicAlignment + minUboAlignment - 1) & ~(minUboAlignment - 1);
|
||||
}
|
||||
```
|
||||
|
||||
The max. allowed alignment (as per spec) is 256 bytes which may be much higher than the data size we actually need for each entry (one 4x4 matrix = 64 bytes).
|
||||
|
|
|
|||
|
|
@ -410,16 +410,19 @@ public:
|
|||
// Allocate data for the dynamic uniform buffer object
|
||||
// We allocate this manually as the alignment of the offset differs between GPUs
|
||||
|
||||
// Calculate required alignment depending on device limits
|
||||
size_t uboAlignment = vulkanDevice->properties.limits.minUniformBufferOffsetAlignment;
|
||||
dynamicAlignment = (sizeof(glm::mat4) / uboAlignment) * uboAlignment + ((sizeof(glm::mat4) % uboAlignment) > 0 ? uboAlignment : 0);
|
||||
// Calculate required alignment based on minimum device offset alignment
|
||||
size_t minUboAlignment = vulkanDevice->properties.limits.minUniformBufferOffsetAlignment;
|
||||
dynamicAlignment = sizeof(glm::mat4);
|
||||
if (minUboAlignment > 0) {
|
||||
dynamicAlignment = (dynamicAlignment + minUboAlignment - 1) & ~(minUboAlignment - 1);
|
||||
}
|
||||
|
||||
size_t bufferSize = OBJECT_INSTANCES * dynamicAlignment;
|
||||
|
||||
uboDataDynamic.model = (glm::mat4*)alignedAlloc(bufferSize, dynamicAlignment);
|
||||
assert(uboDataDynamic.model);
|
||||
|
||||
std::cout << "minUniformBufferOffsetAlignment = " << uboAlignment << std::endl;
|
||||
std::cout << "minUniformBufferOffsetAlignment = " << minUboAlignment << std::endl;
|
||||
std::cout << "dynamicAlignment = " << dynamicAlignment << std::endl;
|
||||
|
||||
// Vertex shader uniform buffer block
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue