"The one catch is that the size of the
bytecode is specified in bytes, but the bytecode pointer is a uint32_t pointer
rather than a char pointer." What was the reason for this?
We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.
Recommending means this is a discussion worth sharing. It gets shared to your followers' Disqus feeds, and gives the creator kudos!
"The one catch is that the size of the
bytecode is specified in bytes, but the bytecode pointer is a uint32_t pointer
rather than a char pointer." What was the reason for this?
I haven't found a source for this, but it's likely the SPIR-V bytecode type.
can som 1 help?
Hi. Pls help me
I have exact same code: C++ code / Vertex shader / Fragment shader
and when i run this code the window (glfw) closing so fast and don`t see any triangle (cin.get() is on). Visual Studio don`t has error.
i try this on Visual Studio 2015 and 2017 enterprise versions.
Before this tutorial (this step), before i had Vertex shader and Fragment shader and addition in c++ main files I saw window whit no problem, but never see any triangle, just white screen.
i have nvidia gtx 650. i use windows system.
Hi. Pls help me
I have exact same code: C++ code / Vertex shader / Fragment shader
and when i run this code the window (glfw) closing so fast and don`t see any triangle (cin.get() is on). Visual Studio don`t has error.
i try this on Visual Studio 2015 and 2017 enterprise versions.
Before this tutorial (this step), before i had Vertex shader and Fragment shader and addition in c++ main files I saw window whit no problem, but never see any triangle, just white screen.
i have nvidia gtx 650. i use windows system.
On windows, a nice little tweak to make the build script for the shaders more version proof, would be to replace the location of the Vulkan SDK: "C:/VulkanSDK/1.0.17.0/" in the case of this tutorial, by the environment variable that LunarG sets. %VK_SDK_PATH%
This way the script doesn't need to be changed if a new version of the Vulkan SDK gets installed.
This way the script is:
%VK_SDK_PATH%/Bin32/glslangValidator.exe -V shader.vert
%VK_SDK_PATH%/Bin32/glslangValidator.exe -V shader.frag
pause
I believe what you describe as clip coordinates are in fact normalized device coordinates. Your vertex shader sets all w-components to 1, so both are identical, but with perspective projection that would not necessarily be the case. Then clip coordinates had to be divided by w to get normalized coordinates (https://www.khronos.org/reg....
Fixed usage of clip coordinates and normalized device coordinates in the tutorial.
Yes, they are also described as "clip coordinates" in the uniform buffers chapter. I use the same name here for consistency. I will modify the image, however.
No. I vaguely recall NVIDIA allowing you to put in GLSL code as well, but only that vendor supports it.
Your editor looks like Sublime Text. If so, where did you get the syntax highlighting for Vulkan?
I don't know if you are still working on this, but a really nice editor for this in my experience has been Atom, it has a monokai theme too and GLSL syntax highlighting.
Makes it look like this for me:
The packages I have installed to work with GLSL a bit more easily are:
autocomplete-glsl //Syntax Autocomplete
language-glsl //Syntax Highlighting
linter-glsl //Error catching
Linter GLSL might not be the best atm, since I think they are trying to catch some errors that are not really errors.
It should be noted that Sublime Text has similar packages:
OpenGL Shading Language (syntax highlighting): https://packagecontrol.io/p...
GLSL Validator (error catching): https://packagecontrol.io/p...
There is even a live GLSL previewer: https://packagecontrol.io/p...
I have looked at previewers too, like this one: https://atom.io/packages/gl...
but none of them seem to work and some are just absolutely obnoxious, like one that just filled the entire workspace with the shader (if it worked to begin with).
A little thing to mention on that though, is that Sublime Text isn't free whereas Atom is :P
The editor is highlight.js (https://highlightjs.org/) which allows you to use the Monokai theme that is also used by Sublime. You can edit the language highlighting files to match extra keywords, so I just modified the C++ highlighting file to also highlight Vulkan functions, types and enumerations. You can see those modifications here: https://github.com/Overv/Vu...
When compiling it to SPIR-V it gives me this error:
ERROR: #version: ES shaders for Vulkan SPIR-V require version 310 or higher
Warning, version 310 is not yet complete; most version-specific features are present, but some are missing.
ERROR: shader.vert:1: 'Ç' : unexpected token
ERROR: shader.vert:1: '' : compilation terminated
ERROR: 3 compilation errors. No code generated.
ERROR: Linking vertex stage: Missing entry point: Each stage requires one entry point
SPIR-V is not generated for failed compile or link
It shows the same error for both shader.frag and shader.vert. It says that it found a character on the first line that was invalid, although it should be fine.
shader.frag:
#version 450
#extension GL_ARB_seperate_shader_objects : enable
layout(location = 0) in vec3 fragColor;
layout(location = 0) out vec4 outColor;
void main() {
outColor= vec4(fragColor, 1.0);
}
shader.vert:
#version 450
#extension GL_ARB_separate_shader_objects : enable
out gl_PerVertex {
vec4 gl_Position;
};
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)
);
vec3 colors[3] = vec3[](
vec3(1.0, 0.0, 0.0),
vec3(0.0, 1.0, 0.0),
vec3(0.0, 0.0, 1.0)
);
void main() {
gl_Position = vec4(positions[gl_VertexIndex], 0.0, 1.0);
fragColor = colors[gl_VertexIndex];
}
How did you (attempt to) compile your shaders?
I downloaded the most recent version of the glslangvalidator and used "glslangValidator -V shader.vert", and this error popped up.
Are you sure you saved the text file without BOM?
Thanks that looks to have fixed it- I just installed notepad++ and changed the type to UTF-8 without BOM
Make sure to return the shaderModule local variable from your createShaderModule function.
I've added that to the tutorial to make sure no one forgets.
It appears as if a lot of HLSL features are already supported by the glslang compiler:
I've done a bit of research but I can't believe that this is actually true: Is it really not possible to use #include in GLSL??? Do I really have to copy paste code around?
Yes, OpenGL has no concept of files. You can implement your own #include, however, because it is basically an automated copy/paste mechanism.
Disaster averted, the LunarG SDK ships with something called glslc (an improved version of glslangvalidator) which supports #include along with many other useful things: https://github.com/google/s...
OpenGL actually allows #include with an extension. However, you have to setup the include-path in the client. But this of course won't work for Vulkan.
Does anyone have any idea on how to set a breakpoint in the .frag or .vert code ? I have Nsight installed on Visual Studio 2015. Is there a where to debug vertex and shader code in vulkan ?
AFAIK there are no ways to set breakpoints in a shader, as it is executed asynchronously on the GPU.
Good point, I will look into this.
Edit: This has now been fixed.
The code should be as portable as possible. Why is it properly aligned with that condition?
It's required by the C++ standard (at least C++11):
Section 5.3.4 New, paragraph 10
... For arrays of char and unsigned char, the difference between the result of the new-expression and the address returned by the allocation function shall be an integral multiple of the strictest fundamental alignment requirement (3.11) of any object type whose size is no greater than the size of the array being created. [ Note: Because allocation functions are assumed to return pointers to storage that is appropriately aligned for objects of any type with fundamental alignment, this constraint on array allocation overhead permits the common idiom of allocating character arrays into which objects of other types will later be placed. —end note ]
Reply to further clarify:
This only applies to std::vector<char> and std::vector<unsigned char> if the default allocator is used, as it is required to allocate memory using operator new.
All of this requirements are met in your code.
Ah, that's very good to know. I'll think about updating the text.
Edit: I've updated the text.
Great tutorial so far, but I have two questions (possibly the answers are related?):
1) Why is readFile() static?
2) Wouldn't it be more efficient to pass a reference to a std::vector object to readFile() instead of returning a std::vector object? Because afaik in the latter case the object from readFile() would be copied and depending on the size of the file that might lead to unecessary memory consumption (not to mention the additional time for copying the object)
1) Because it doesn't access any class instance variables/members.
2) A C++11 compiler will not copy the vector, but instead use the move constructor. See: http://stackoverflow.com/qu...
Interesting, I didn't know that either of those were a thing, I guess you learn something new every day :)
i am stuck at compiling the shaders to SPIR-V. Here is the output
E:\Users\Alex\Workspace\Projects\Development\CellarDoor\source\Gin.Graphics.Vulkan.Playground\shaders>%VULKAN_SDK%/Bin/glslangValidator.exe -V shader.frag
shader.frag
ERROR: #version: ES shaders for Vulkan SPIR-V require version 310 or higher
Warning, version 310 is not yet complete; most version-specific features are present, but some are missing.
ERROR: shader.frag:1: '´' : unexpected token
ERROR: shader.frag:1: '' : compilation terminated
ERROR: 3 compilation errors. No code generated.
Linked fragment stage:
ERROR: Linking fragment stage: Missing entry point: Each stage requires one entry point
SPIR-V is not generated for failed compile or link
E:\Users\Alex\Workspace\Projects\Development\CellarDoor\source\Gin.Graphics.Vulkan.Playground\shaders>
Happens with both, vert and frag shaders. Both shaders are the ones from this tutorial. I dont know why the compiler is complaining about ES version 310.
My GPU is Nvidia GTX660 with Nvidia Driver 376.19
Does anyone know a reason for this behavior?
found out that when i created a text file for the shader in visual studio, visual studio saved the file along with a ByteOrderMark which causes the compiler to fail.
Are you 100% sure that you used the right shader.frag file? Because there is no backtick (`) anywhere in the shaders on this page.
yes, its the right shader. The backtick bothered me too. In the end it was a byte order mark at the beginning of the file. Without that mark it compiles perfectly.
Just a small typo: change "The main function is invoked for every vertex the built-in gl_VertexIndex variable contains the index of the current vertex." to "The main function is invoked for every vertex. The built-in gl_VertexIndex variable contains the index of the current vertex."
By the way, having the little .bat file contain:
@for %%i IN (*.vert; *.tesc; *.tese; *.geom; *.frag; *.comp) DO (C:/VulkanSDK/1.0.26.0/Bin32/glslangValidator.exe -V "%%i")
pause
will compile all the shader files in the directory! (with the right SDK path, of course)
The validator defaults to naming files "<stage>.spv" So if you have multiple shaders for the same stage they'll just get overwritten. Can do
@for %%I IN (*.vert; *.tesc; *.tese; *.geom; *.frag; *.comp) DO (%VULKAN_SDK%/Bin32/glslangValidator.exe -V "%%I" -o "%%~nI%%~xI.spv")
pause
to name things <filename>.<stage>.spv if you want to compile everything at the same time.
Alexander Overvoorde — Yes, but you still need to synchronise the host writing with shader reads.
Sri Harsha Chilakapati — Thanks man, that cleared up things.
Alexander Overvoorde — Yeah, you can flip [0][0] as well.
Alexander Overvoorde — I consider it simply a matter of preference, because even without optimization flags it makes no difference: …