mojira.dev
MC-307206

Std140Builder incorrectly pads vec3s and ivec3s

Std140Builder doesnt account for the fact that if you have a 4 byte type following a 12 byte type, it can sneakily fit into the 4 byte gap, instead it reserves 16 bytes and places the 4 byte type after that

this is well documented as how layouts are supposed to work, but as something that is often handled incorrectly (as it is here)

This can only be observed with a custom resourcepack, as follows:

  • apply attached resourcepack (std140bug.zip)

  • spectate a creeper

  • the screen should match the bottom screenshot in the attached image, but it instead matches the top one

  • this happens because the shader has a float after a vec3 in its uniform block, which leads to minecraft incorrectly padding the buffers more than the shader code is expecting

from modding the game myself, it seems the solution is to remove the lines that advance 4 bytes at the end of putVec3() and putIVec3(), and to change the +16 advancing in the org.joml overloads of those functions to +12. the align() function already inserts 4 extra bytes of padding if it needs to

Std140SizeCalculator should also be changed to account for this, otherwise it will allocate slightly more buffer space than strictly necessary, i think this is also as easy as changing it to only add 12 for the vec3 functions, but i havent tested this

Attachments

Comments 1

Thank you for helping us improve Minecraft! We saved your files:

[media][media]

Nettakrim

(Unassigned)

Unconfirmed

(Unassigned)

26.1.1

Retrieved