This PR introduces optional support for a per-primitive header in vertex buffer data, and rewrites the "XHFP" vertex format (used by Iris for shader packs) to make use of it. This is a technique more broadly known as "vertex pulling", where rather than using native OpenGL vertex attributes, the vertex shader explicitly fetches the desired data from the buffer. The changes were done in collaboration with Claude Opus 5.5. About 1/3-1/2 of the added lines are tests or boilerplate like the GLSL generator for the fetching abstraction.
The bullet points below explain various design decisions, tradeoffs, performance measurements, etc in no particular order.
SSBOs were intentionally not used, to stay compatible with older OpenGL versions. One downside is that we lose a texture unit (unimportant for vanilla, might matter if a shaderpack exists that needs all previously unused units concurrently, but I doubt one exists).
The pulling logic is abstracted behind a generator, both to make it very pleasant to use from a shader writing perspective, and also so that branches are not needed when pulling is on or off. This matters because...
Pulling is currently not enabled for all formats by default. On my RX 6600, it shows a very small (~2.5%) regression in a vertex-bound synthetic benchmark of the terrain shader, where memory bandwidth was not a limitation. Since Minecraft is often not truly vertex-bound (at least in terms of ALU work), and memory bandwidth is definitely an issue at real render distances, pulling may still work out to be net positive there. This needs more testing.
Future work enabling pulling on the vanilla/built-in portions of the vertex format can move the rdh factor and the draw ID/material to the shared header. We should also investigate whether a more optimal CVF is possible when we have ability to read all four vertices from the shader. Previous implementations were limited by only being able to look at data for a single vertex at a time.
We currently replace even the per-vertex attributes with pulling in formats where a header is used. We considered a hybrid setup where we still use some vertex attributes, and rejected it due to additional complexity not being worth the 2%. (There are other ways to get back some of the 2%, like fetching 8 bytes at a time in the generated code instead of 4-byte.)
Previously XHFP was 192 bytes per quad. It's now down to 120 bytes per quad, which works out to 30 bytes per vertex. This is less memory overall than the vanilla-like format (when the latter is not pulled).
This PR introduces optional support for a per-primitive header in vertex buffer data, and rewrites the "XHFP" vertex format (used by Iris for shader packs) to make use of it. This is a technique more broadly known as "vertex pulling", where rather than using native OpenGL vertex attributes, the vertex shader explicitly fetches the desired data from the buffer. The changes were done in collaboration with Claude Opus 5.5. About 1/3-1/2 of the added lines are tests or boilerplate like the GLSL generator for the fetching abstraction.
The bullet points below explain various design decisions, tradeoffs, performance measurements, etc in no particular order.
SSBOs were intentionally not used, to stay compatible with older OpenGL versions. One downside is that we lose a texture unit (unimportant for vanilla, *might* matter if a shaderpack exists that needs all previously unused units concurrently, but I doubt one exists).
The pulling logic is abstracted behind a generator, both to make it very pleasant to use from a shader writing perspective, and also so that branches are not needed when pulling is on or off. This matters because...
Pulling is currently not enabled for all formats by default. On my RX 6600, it shows a very small (~2.5%) regression in a vertex-bound synthetic benchmark of the terrain shader, where memory bandwidth was not a limitation. Since Minecraft is often not truly vertex-bound (at least in terms of ALU work), and memory bandwidth is definitely an issue at real render distances, pulling may still work out to be net positive there. This needs more testing.
Future work enabling pulling on the vanilla/built-in portions of the vertex format can move the rdh factor and the draw ID/material to the shared header. We should also investigate whether a more optimal CVF is possible when we have ability to read all four vertices from the shader. Previous implementations were limited by only being able to look at data for a single vertex at a time.
We currently replace even the per-vertex attributes with pulling in formats where a header is used. We considered a hybrid setup where we still use some vertex attributes, and rejected it due to additional complexity not being worth the 2%. (There are other ways to get back some of the 2%, like fetching 8 bytes at a time in the generated code instead of 4-byte.)
Previously XHFP was 192 bytes per quad. It's now down to 120 bytes per quad, which works out to 30 bytes per vertex. This is less memory overall than the vanilla-like format (when the latter is not pulled).
Formats are described by one layout, and the GLSL that supplies their inputs is generated from it, so attribute fetch and pulling read the same data with the same conversions. Pulling is off by default; -Dceleritas.preferVertexPulling=true enables it for formats that also support attributes.
Vertex inputs that packs declare are now declared by the generated header with the pack's types, so they can be pulled too. The active texture unit is restored through GlStateManager, since Iris leaves the lightmap unit active.
at_midBlock is no longer stored either; the transformer derives it from the block's position within its section. A quad now takes 132 bytes instead of 192.
XHFP no longer stores them, so a quad takes 120 bytes. The mid texcoord is computed in texture units, which makes the raw-unit scaling in replaceMidTexCoord unnecessary.
embeddedt
marked the pull request as ready for review 2026-10-30 15:00:38 -04:00
embeddedt
manually merged commit 0cb43ed432 into stonecutter2026-10-30 15:00:42 -04:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
This PR introduces optional support for a per-primitive header in vertex buffer data, and rewrites the "XHFP" vertex format (used by Iris for shader packs) to make use of it. This is a technique more broadly known as "vertex pulling", where rather than using native OpenGL vertex attributes, the vertex shader explicitly fetches the desired data from the buffer. The changes were done in collaboration with Claude Opus 5.5. About 1/3-1/2 of the added lines are tests or boilerplate like the GLSL generator for the fetching abstraction.
The bullet points below explain various design decisions, tradeoffs, performance measurements, etc in no particular order.
SSBOs were intentionally not used, to stay compatible with older OpenGL versions. One downside is that we lose a texture unit (unimportant for vanilla, might matter if a shaderpack exists that needs all previously unused units concurrently, but I doubt one exists).
The pulling logic is abstracted behind a generator, both to make it very pleasant to use from a shader writing perspective, and also so that branches are not needed when pulling is on or off. This matters because...
Pulling is currently not enabled for all formats by default. On my RX 6600, it shows a very small (~2.5%) regression in a vertex-bound synthetic benchmark of the terrain shader, where memory bandwidth was not a limitation. Since Minecraft is often not truly vertex-bound (at least in terms of ALU work), and memory bandwidth is definitely an issue at real render distances, pulling may still work out to be net positive there. This needs more testing.
Future work enabling pulling on the vanilla/built-in portions of the vertex format can move the rdh factor and the draw ID/material to the shared header. We should also investigate whether a more optimal CVF is possible when we have ability to read all four vertices from the shader. Previous implementations were limited by only being able to look at data for a single vertex at a time.
We currently replace even the per-vertex attributes with pulling in formats where a header is used. We considered a hybrid setup where we still use some vertex attributes, and rejected it due to additional complexity not being worth the 2%. (There are other ways to get back some of the 2%, like fetching 8 bytes at a time in the generated code instead of 4-byte.)
Previously XHFP was 192 bytes per quad. It's now down to 120 bytes per quad, which works out to 30 bytes per vertex. This is less memory overall than the vanilla-like format (when the latter is not pulled).