Unexpected output from Hello Triangle vulkan-tutorial #1496
Unanswered
JesseRMeyer
asked this question in
Q&A
Replies: 1 comment
-
By changing the fragment shader to .. : #version 450
layout(location = 0) out vec3 fragColor;
vec2 positions[3] = vec2[](
vec2(0.0, -0.5),
vec2(0.5, 0.5),
vec2(-0.5, 0.5)
);
void main() {
gl_Position = vec4(positions[gl_VertexIndex], 0.0, 1.0);
vec3 color = vec3(1.0, 1.0, 1.0);
if (gl_VertexIndex == 0) {
color = vec3(1.0, 0.0, 0.0);
}
else if (gl_VertexIndex == 1) {
color = vec3(0.0, 1.0, 0.0);
}
else {
color = vec3(0.0, 0.0, 1.0);
}
fragColor = color;
} .. the magical rainbow triangle appears! While I don't know if this difference is ultimately caused by MoltenVK or Intel, I'm going to upgrade this discussion to an issue proper here now. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Instead of filing an issue, I wanted to clarify what the expected output of the now well know vulkan-tutorial (https://vulkan-tutorial.com) should be on MoltenVK nearly* out of the box. I suspect to have tripped over either a MoltenVK or Intel GFX driver bug. Fortunately, the official MoltenVK cube program seems to work as expected, which presumably exercises the foundational aspects of vulkan->metal wrapper. So finding an even more minimal program with unexpected output caught me by surprise.
Edit: I've tested with the following validation features enabled, with no difference (no warnings emitted, etc): BEST_PRACTICES, GPU_ASSISTED_RESERVE_BINDING_SLOT, DEBUG_PRINTF, SYNCHRONIZATION_VALIDATION. (Not that DEBUG_PRINTF would work here anyway, unless I made a configuration mistake due to a misunderstanding).
What I expected to see:
What I saw:
Nearly* : I had to make two simple adjustments to the code listed here to appease the validation layers as per the MoltenVK documentation: code
The vertex and fragment shader are as follows in GLSL.
Curious, I captured the metal frame render via Xcode.
Notice how the vertices are being correctly accessed and stored as a direct function of
gl_VertexIndex
, but the color is not. Oddly, the last vertex appears to get the first color, although this could be coincidence, and all prior vertices get some default 0.0 (not even a possible choice in the array), implying the zero initialization ofmain0_out out = {};
was never overwritten.Here is the final transformation for both shaders to Metal. I don't see anything glaringly wrong. We can see that flipping the y dimension for the output vertex is correctly being applied. This would seem to suggest that array access via gl_VertexIndex works, and that accesses to the store variable also work. But for some inexplicable reason, this is violated for out.fragColor. I think we can all agree that the output is at least unexpected, but I'm not sure how to continue the investigation from here lacking shader printf / RenderDoc support.
C++ code built via:
clang++ -std=c++17 vulkan_cpp.cpp -I/usr/local/Cellar/glfw/3.3.6/include/ -I/Users/<redacted>/VulkanSDK/1.2.198.1/macOS/include/ -o v_tutorial -L/usr/local/Cellar/glfw/3.3.6/lib/ -L/Users/<redacted>/VulkanSDK/1.2.198.1/macOS/lib/ -lglfw -lvulkan
Both shaders were compiled following the form
glslc <shader file name> -g -O0 -o <shader stage name>.spv
Vulkan API dump: gist here
OSX Monterey 12.1
Intel HD Graphics 5000
Beta Was this translation helpful? Give feedback.
All reactions