-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.9.2
-
None
-
Windows 11, Visual Studio 2022
-
-
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 |
672833,3 | WIP: Explore how non-zero base instance adjustment could be enabled for D3D | dev | qt/qtshadertools | Status: NEW | -2 | 0 |
674518,3 | rhi: Add an InstanceIndexIncludesBaseInstance feature query | dev | qt/qtbase | Status: MERGED | +2 | 0 |