I've moved a Visual Studio project to a different computer and now GLSL won't compile shaders which previously worked fine. It's getting stuck implicitly converting vec4s to vec3s and it tells me the 'dot' function is undefined, for example.
I'm using the GLSDK and the project builds correctly, and glGetString(GL_SHADING_LANGUAGE_VERSION) tells me 4.40. It's obviously something I don't have installed but used to, but I've searched around and cannot work out what.
Sorry, it sounds like your old drivers were being a bit too permissive. Your new drivers are correct in rejecting the shaders.
vec4 a = vec4(1.0, 2.0, 3.0, 4.0);
vec3 x = vec3(a); // Ok
// vec3 y = a; error
Indeed, if I run the implicit conversion through the reference compiler, I get the following error message:
ERROR: 0:4: '=' : cannot convert from '4-component vector of float' to '3-component vector of float'
ERROR: 1 compilation errors. No code generated.
Try validating your scripts with the reference compiler, it may catch some portability issues like these. Your only real option here is to fix the broken shaders.
What about dot()?
Try this:
#version 330
void main() {
vec4 x = vec4(1.0);
vec3 y = vec3(2.0);
float z = dot(x, y);
}
When I run the validator, I get:
ERROR: 0:5: 'dot' : no matching overloaded function found
ERROR: 1 compilation errors. No code generated.
The error here is that my arguments to dot() are the wrong type. Again, the problem is in my shader.
Related
I have an Intel HD Graphics 530 (Skylake GT2) GPU. Installed MESA 13.1 drivers on Ubuntu 16.04 LTS.
I wrote a shader that makes use of an usampler2D, and therefore was trying to use #extension GL_EXT_gpu_shader4. Apparently this is not supported by this GPU, but #extension GL_EXT_texture_integer is. Also, #version 130 is supported.
However, I cannot use usampler2D nor texture2D(usampler2D) using none of the combinations of
#version 120
#extension GL_EXT_texture_integer
uniform usampler2D tex;
void main() { texture2D(tex, vec2(0., 0.)); }
nor
#version 130
uniform usampler2D tex;
void main() { texture2D(tex, vec2(0., 0.)); }
None of the shader version compile successfully. Both yield errors of undefined overload of texture2D(usampler), only texture2D(sampler) overloads are apparently supported.
0:20(18): error: no matching function for call to `texture2D(usampler2D, vec2)'; candidates are:
0:20(18): error: vec4 texture2D(sampler2D, vec2)
0:20(18): error: vec4 texture2D(sampler2D, vec2, float)
Is there an alternative of using usampler2D uniforms on this architecture? Or maybe I'm using wrong driver configs?
texture2D cannot be used with usamplers of any kind. texture2D was deprecated from GLSL 1.30 and removed in GLSL 1.50.
The correct function to use is texture. This requires GLSL 1.30 or higher, or EXT_gpu_shader4.
I encountered a compiler crash and intellisense false positives with Visual Studio 2015 using C++.
This crashes the compiler when written within a function block:
if();
This is the dialog that is shown when compiling (I am on a German version of Windows):
Even though the compiler crashes, I get error list output:
Error C2059 syntax error: ')'
Warning C4390 ';': empty controlled
statement found; is this the intent?
Error C1903 unable to recover from previous error(s); stopping compilation
This produces squiggles and error annotations in the vertical scrollbar in map mode, but no actual intellisense errors:
#include <vector>
struct S { std::vector<S> Children; };
int main(int argc, char* argv[]) {
S item;
item.Children.push_back(S());
// ^
// Error: no instance of overloaded function
// "std::vector<_Ty, _Alloc>::push_back [with _Ty=S, _Alloc=std::allocator<S>]"
// matches the argument list
// argument types are: (S)
// object type is: std::vector<S, std::allocator<S>>
S& back = item.Children.back();
// ^^^^
// Error: a reference of type "S &" (not const-qualified) cannot be
// initialized with a value of type "S"
return 0;
}
Are those bugs? Are they known? Can you reproduce them?
For the first case: the compiler shouldn't crash but just issue the diagnostic you show. So yes, that's a bug. Which doesn't occur in VS2013 btw. Submit a report for it here
For the second case: it is the same in VS2013 and is due to nesting a vector of S inside S. This and other cases make the error squiggles appear incorrectly, it is actually not that uncommon. But ideally it should not happen so you can submit a bug report for it as well, though it might be something which is going to be labelled 'wontfix' as the compiler team usually focusses on more urgent cases.
I'm working on a piece of code in OpenGL.
I'm getting the following error message while trying to compile:
MyGLWidget.cpp: In member function ‘virtual void MyGLWidget::initializeGL()’:
MyGLWidget.cpp:30:38: error: cannot convert ‘glm::vec3 {aka glm::tvec3<float, (glm::precision)0u>}’ to ‘const GLfloat* {aka const float*}’ in argument passing
MyGLWidget.cpp:31:39: error: cannot convert ‘glm::vec3 {aka glm::tvec3<float, (glm::precision)0u>}’ to ‘const GLfloat* {aka const float*}’ in argument passing
I have declared these locations in MyGLWidget.h as follows:
GLuint llumLoc, focusLoc;
And have initialize them in MyGLWidget.cpp as:
llumLoc = glGetUniformLocation (program->programId(), "llumAmbient");
focusLoc = glGetUniformLocation (program->programId(), "posFocus");
"llumAmbient" and "posFocus" are uniforms in my vertex shader:
uniform vec3 llumAmbient;
uniform vec3 posFocus;
I get the mentioned error message while trying to call the following code inside of MyGLWidget::initializeGL
glUniform3fv(llumLoc, 1, glm::vec3(0.2));
glUniform3fv(focusLoc, 1, glm::vec3(1.0));
Obviously, I've tried to follow the documentation at www.opengl.org and glm.g-truc.net/0.9.2/api/a00001.html, but I just can't see what's wrong with this code...
Actually, I just found out today that there's a cleaner and more straight forward way. Simply:
glUniform3fv(focusLoc, 1, &v[0]);
No need to import value_ptr.
You need to give a pointer to the vector, not the vector itself. For example:
glm::vec3 v(1.0f);
glUniform3fv(focusLoc, 1, glm::value_ptr(&v[0]));
I'm trying to apply the log2 onto a __m128 variable. Like this:
#include <immintrin.h>
int main (void) {
__m128 two_v = {2.0, 2.0, 2.0, 2.0};
__m128 log2_v = _mm_log2_ps(two_v); // log_2 := log(2)
return 0;
}
Trying to compile this returns this error:
error: initializing '__m128' with an expression of
incompatible type 'int'
__m128 log2_v = _mm_log2_ps(two_v); // log_2 := log(2)
^ ~~~~~~~~~~~~~~~~~~
How can I fix it?
The immintrin.h you look into and immintrin.h used for compilation are different.
Likely, you're looking into Intel-specific header (somewhere like /opt/intel/include/immintrin.h), while your compiler uses default immintrin.h
As it was correctly said, extern __m128 _mm_log2_ps(__m128 v1) is SVML routine, so
the very first solution I see is to use Intel Compiler. For non-commercial development its free for Linux.
Although you can specify the include path to your custom immintrin.h file as a very first argument during compilation using different compiler, but I think you'll get just way too many errors - just because this header is Intel-specific.
I'm trying to use the Gl3n (https://bitbucket.org/dav1d/gl3n) but
I keep getting error 42 whenever I try this:
alias Vector!(float, 2) vect2;
vect2 position;
position.x = 2.0f; //This is what causes the error
I looked into how the struct was implemented and x is an alias
for a get/set function that interacts with the array that stores
the values for the vector. I've tried something like this:
alias Vector!(float, 2) vect2;
vect2 position;
position = vect2(0.0f, 0.0f);
However, both methods give the same error:
Error 42: Symbol Undefined pure nothrow #property #safe void
gl3n.linalg.Vector!(float,
2).Vector.set_!('x').set_(float) C:\Users\CP\Documents\Visual
Studio 2010\Projects\D\STDS\
Error 42: Symbol Undefined
_D4gl3n6linalg16__T6VectorTfVi2Z6Vector6__initZ
I have the module linalg imported like this at the top:
import Gl3n.linalg; //Gl3n is the folder the source files are in
If I remember correctly, Error 42 is the linker error (optlink).
I don't remember the linker flag, but you need to tell the linker where the library is (gl3n.lib I suppose).
You can use pragma(lib, "gl3n.lib") at the top of your main file assuming gl3n.lib is located in the directory you are compiling from.