mojira.dev
MC-307973

gl_InstanceID does not work correctly with Vulkan

gl_InstanceID does not work correctly with Vulkan

Steps to reproduce the bug:

  1. Apply the attached resource pack with Vulkan

  2. Enable the “Improved transparency” setting

  3. Check the water rendering

  4. Do the same thing with OpenGL

Expected behavior:

The water should be rendered like OpenGL

Code analysis:

   @Override
   public void draw(final int firstVertex, final int vertexCount) {
      if (this.pipeline != null && this.pipeline.isValid()) {
         this.pushDescriptors();
         VK12.vkCmdDraw(this.secondaryCommandBuffer(), vertexCount, 1, firstVertex, vertexCount);
      }
   }

The Vulkan signature is vkCmdDraw(cmd, vertexCount, instanceCount, firstVertex, firstInstance). The 5th argument firstInstance is set to vertexCount instead of 0.

Consequence: gl_InstanceIndex in any vertex shader will equal vertexCount instead of 0 for non-indexed draw() calls. Any shader that reads gl_InstanceIndex (for instancing, per-instance SSBO lookups, etc.) will have a shifted index.

Attachments

Comments 2

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

[media]

Lolo

(Unassigned)

Community Consensus

26.2 Snapshot 6

26.2 Snapshot 7

Retrieved