Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-139565

Incorrect gl_InstanceIndex on D3D11 and D3D12

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P2: Important P2: Important
    • None
    • 6.9.2
    • Qt RHI
    • None
    • Windows 11, Visual Studio 2022
    • Windows
    • 73a18c3eb (dev)

      The vertex shader input variable gl_InstanceIndex should count from the base instance, i.e.

          base, base+1, ..., base+count-1

      see https://github.com/KhronosGroup/GLSL/blob/main/extensions/khr/GL_KHR_vulkan_glsl.txt , line 580.
      This works as expected with the Vulkan backend. But with the D3D11 and D3D12 backends, gl_InstanceIndex incorrectly counts from 0, i.e.

          0, 1, ..., count-1 .

      I have written a bare bones example program that demonstrates the issue.
      It draws a single quad using the command

          commandBuffer->draw(4, 1, 0, 100);

      The vertex shader then sets the color as follows

          if (gl_InstanceIndex == 0)
              fragColor = vec3(1.0, 0.0, 0.0);
          else if (gl_InstanceIndex == 100)
              fragColor = vec3(0.0, 1.0, 0.0); // expected
          else
              fragColor = vec3(0.0, 0.0, 0.0);

      The expected behavior is to get a green quad.
      But with D3D11 and D3D12 I get a red quad.

      The code can be downloaded from https://github.com/jrade/InstanceIndexIssue .
      The RHI backend can be set in the main function.
      The shaders can be baked with the script Resources/BakeShaders.bat.

      The code was tested with Windows 11, Visual Studio 2022, Qt 6.9.2
      and both an NVIDIA GeForce and an Intel Iris GPU.

        For Gerrit Dashboard: QTBUG-139565
        # Subject Branch Project Status CR V

            lagocs Laszlo Agocs
            jrade Johan Råde
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:

                There is 1 open Gerrit change