1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-09 12:50:35 +00:00

Align Vertex Buffer to 4 Bytes

With the octahedral compression, we had attributes of a size of 2 bytes
which potentially caused performance regressions on iOS/Mac

Now add padding to the normal/tangent buffer

For octahedral, normal will always be oct32 encoded
UNLESS tangent exists and is also compressed
then both will be oct16 encoded and packed into a vec4<GL_BYTE>
attribute
This commit is contained in:
Omar El Sheikh
2021-08-06 12:34:29 -04:00
parent 8db0bd4424
commit f0de7ec2b6
5 changed files with 59 additions and 56 deletions

View File

@@ -3397,15 +3397,15 @@ void RasterizerStorageGLES3::mesh_add_surface(RID p_mesh, uint32_t p_format, VS:
} break;
case VS::ARRAY_NORMAL: {
if (p_format & VS::ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION) {
// Always pack normal and tangent into vec4
// normal will be xy tangent will be zw
// normal will always be oct32 (4 byte) encoded
// UNLESS tangent exists and is also compressed
// then it will be oct16 encoded along with tangent
attribs[i].normalized = GL_TRUE;
attribs[i].size = 2;
if (p_format & VS::ARRAY_COMPRESS_NORMAL) {
attribs[i].type = GL_BYTE;
attributes_stride += 2;
} else {
attribs[i].type = GL_SHORT;
attributes_stride += 4;
}
attribs[i].size = 4;
attribs[i].type = GL_SHORT;
attributes_stride += 4;
} else {
attribs[i].size = 3;
@@ -3423,13 +3423,14 @@ void RasterizerStorageGLES3::mesh_add_surface(RID p_mesh, uint32_t p_format, VS:
} break;
case VS::ARRAY_TANGENT: {
if (p_format & VS::ARRAY_FLAG_USE_OCTAHEDRAL_COMPRESSION) {
attribs[i].normalized = GL_TRUE;
attribs[i].size = 2;
attribs[i].enabled = false;
if (p_format & VS::ARRAY_COMPRESS_TANGENT) {
attribs[i].type = GL_BYTE;
attributes_stride += 2;
// normal and tangent will each be oct16 (2 bytes each)
// pack into single vec4<GL_BYTE> for memory bandwidth
// savings while keeping 4 byte alignment
attribs[VS::ARRAY_NORMAL].type = GL_BYTE;
} else {
attribs[i].type = GL_SHORT;
// normal and tangent will each be oct32 (4 bytes each)
attributes_stride += 4;
}
} else {