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, which once again only needs the +16 to size changed to 12, and the alignment kept as is

Attachments

Comments 2

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

[media][media]

Nettakrim

(Unassigned)

Community Consensus

Platform G

Low

Rendering

26.1.1

26.3 Snapshot 6

Retrieved