KhronosGroup / OpenGL-API

OpenGL and OpenGL ES API Issue Tracker
34 stars 5 forks source link

std140 layout doesn't specify the total memory consumed #67

Closed YunHsiao closed 4 years ago

YunHsiao commented 4 years ago

All specifications regarding std140, a supposed-to-be cross vender memory layout, seems to have no mentioning of how much memory should be allocated in total say for a given UBO (i.e. UNIFORM_BLOCK_DATA_SIZE) like this:

uniform Test {
  float x;
};

And in fact there has already been different interpretations over implementations, see the discussion here.

oddhack commented 4 years ago

Moving to API repo.

pdaniell-nv commented 4 years ago

I believe the std140 definition is only concerned with the placement of elements in memory, it does not dictate how much space the whole block takes up. The query to GL_BUFFER_DATA_SIZE is implementation-dependent. From the OpenGL ES 3.2 spec (page 88):

For the property BUFFER_DATA_SIZE, a single integer identifying the
implementation-dependent minimum total buffer object size is written to params.
This value is the size, in basic machine units, required to hold all active variables
associated with an active uniform block, atomic counter buffer, or shader storage
block. If the final member of an active shader storage block is an array with no declared size, the minimum buffer size is computed assuming the array was declared
as an array with one element.

Different implementations may have different padding requirements, which is why this value might vary between implementations.

YunHsiao commented 4 years ago

Oh my mistake, apologies. Thanks for clarifying.