Unsupported usampler - opengl

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.

Related

Cannot compile `enqueue_kernel` on opencl 2.1 NEO device

I have the following code on the device Intel(R) Gen9 HD Graphics NEO -- OpenCL 2.1 NEO :
__kernel void update(
const __global uint* positions,
const __global float3* offsets,
const int size,
__global int* cost
) {
int global_id = get_global_id(0);
if (global_id >= size) {
return;
}
int3 update_index = position_from_index(grid_centroid_positions[global_id], SIZE) -
offset_grid;
ndrange_t ndrange = ndrange_3d(size, size, size);
enqueue_kernel(get_default_queue(), ndrange,
^{update_surrouding_cells(offsets, global_id, update_index, update_edge_size, size, cost)});
}
But i get the following compiler error:
6:158:5: error: use of undeclared identifier 'ndrange_t'
ndrange_t ndrange = ndrange_3d(size, size, size);
^
6:161:5: error: implicit declaration of function 'enqueue_kernel' is invalid in OpenCL
enqueue_kernel(get_default_queue(), ndrange,
^
6:161:20: error: implicit declaration of function 'get_default_queue' is invalid in OpenCL
enqueue_kernel(get_default_queue(), ndrange,
^
6:162:163: error: expected ';' after expression
^{update_surrouding_cells(offsets, global_id, update_index, update_edge_size, size, cost)});
^
;
6:161:41: error: use of undeclared identifier 'ndrange'
enqueue_kernel(get_default_queue(), ndrange,
Compilation options are as follows:
-I "/home/development/cl" -g
-D SIZE=256
The device supports opencl 2.1, yet when compiling it seems none of the things for enqueue_kernel exist. Do i need a special extension or something? I am reading the spec here, but it doesn't seem to say anything about actually compiling the examples with dynamic parallelism.
When compiling, it is not just the version of the device that is important. The compiled version of cl code is passed into the compilation options. AKA the compilation options when compiling the opencl program (kernel code) should include:
-cl-std=CL2.0
Or the specific standard that you are looking for.

glUniform3fv not working OpenGL

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]));

Type mismatch with glLightfv

I have configured the OpenGL environment under windows, I use VS2010.
When I wrote this code: glLightfv(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 1.5), I got a warning type mismatch message.
I also got this informations:
IntelliSense, "double type" real participation "const GLfloat *" type
parameter is not compatible with f: \ lirui \ project \ opengltest \
opengltest \ opengltest 22 50 opengltest CPP
The parameter 1.5 is of type double while glLightfv needs a const GLfloat *.
When you specify pname to be GL_CONSTANT_ATTENUATION, the documentation says:
params is a single integer or floating-point value...
So you should use glLightf (or glLighti) instead of glLightfv.
You may give it a float (or an integer) instead of a double to avoid unnecessary cast:
glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 1.5); // what you want
glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 1.5f); // what you want (avoid a cast)
glLighti(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 1); // what you may want

Missing GLSL functionality

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.

CUDA 5.5 nvlink undefined reference (inheritance)

I've been working on my GPU-raytracer implementation, but as I am new to CUDA I have some problems with compiling and linking the separate .cu files.
My 2 classes: Shader and Lambert. Lambert inherits the interface Shader. When I compile I recieve the following errors:
Error 4 error MSB3721: The command ""G:\Development\CUDA Toolkit\CUDA Toolkit v5.5\bin\nvcc.exe"
-dlink -o "Debug\CUDA RayTracer.device-link.obj" -Xcompiler "/EHsc /W3 /nologo /Od /Zi /RTC1
/MDd " -L"P:\My Projects\CUDA Ray-Tracer\CUDA RayTracer\ThirdParty\SDL\lib\x86" -L"P:\My
Projects\CUDA Ray-Tracer\CUDA RayTracer\CUDA RayTracer\\..\ThirdParty" -L"G:\Development\CUDA
Toolkit\CUDA Toolkit v5.5\lib\Win32" cudart.lib kernel32.lib user32.lib gdi32.lib winspool.lib
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib
SDL.lib SDLmain.lib -gencode=arch=compute_30,code=sm_30 -G --machine 32 Debug\Camera.cu.obj
Debug\IShader.cu.obj Debug\Lambert.cu.obj Debug\Matrix.cu.obj Debug\Plane.cu.obj
Debug\sdl.cu.obj Debug\cuda_renderer.cu.obj" exited with code -1.
C:\Program Files(x86)\MSBuild\Microsoft.Cpp\v4.0\V110\BuildCustomizations\CUDA 5.5.targets 668
1>nvlink : error : Undefined reference to '_ZN6ShaderD1Ev' in 'Debug/IShader.cu.obj'
1>nvlink : error : Undefined reference to '_ZN6ShaderD0Ev' in 'Debug/IShader.cu.obj'
1>nvlink : error : Undefined reference to '_ZN6ShaderD2Ev' in 'Debug/Lambert.cu.obj'
I have no idea what '_ZN6ShaderD1Ev' means, I think everything is correct in my implementation (C++ wise, not sure what CUDA thinks about it). As far as I know CUDA 5.5 supports virtual functions and inheritance.
I have installed CUDA 5.5 Toolkit and I have enabled the "Generate Relocatable Device Code" in my Visual Studio 2012. Also I've set 'compute_30,sm_30'in order to use 'operator new' (my graphics card is capable of it - GTX670MX). My project consists only of .cu and .cuh files.
My source code:
//IShader.cuh
#ifndef I_SHADER_H
#define I_SHADER_H
#include "Vector3D.cuh"
#include "Color.cuh"
#include "IGeometry.cuh"
__device__ extern Vector cameraPos;
__device__ extern Vector lightPos;
__device__ extern Color lightColor;
__device__ extern float lightPower;
__device__ extern Color ambientLight;
class Shader
{
protected:
Color _color;
public:
__device__ Shader(const Color& color);
__device__ virtual ~Shader();
__device__ virtual Color shade(Ray ray, const IntersectionData& data) = 0;
};
#endif
//IShader.cu
#include "IShader.cuh"
__device__ Shader::Shader(const Color& color)
{
this->_color = color;
}
// Lambert.cuh
#ifndef LAMBERT_H
#define LAMBERT_H
#include "IShader.cuh"
class Lambert : public Shader
{
public:
__device__ Lambert(const Color& diffuseColor);
__device__ Color shade(Ray ray, const IntersectionData& data);
};
#endif
//Lambert.cu
#include "Lambert.cuh"
Vector cameraPos;
Vector lightPos;
Color lightColor;
float lightPower;
Color ambientLight;
__device__ Lambert::Lambert(const Color& diffuseColor)
: Shader(diffuseColor)
{
}
__device__ Color Lambert::shade(Ray ray, const IntersectionData& data)
{
Color result = _color;
result = result * lightColor * lightPower / (data.p - lightPos).lengthSqr();
Vector lightDir = lightPos - data.p;
lightDir.normalize();
double cosTheta = dot(lightDir, data.normal);
result = result * cosTheta;
return result;
}
If you need more code I could give you link to github repo.
I hope you can help me.
Thanks in advance!
C++ enables different entities (e.g., functions) named with the same identifier to belong to different namespaces. To uniquely resolve names, the compiler uses name mangling, that is, it encodes additional information in the name of the involved entities. This is the reason why nvlink is referring to this "obscure" entity _ZN6ShaderD1Ev. In order to restore a more understandable name, a demangling operation is necessary.
Although demangling software exist, I'm often using an online demangler
c++filtjs
Using this page, you can discover that
_ZN6ShaderD1Ev
actually means
Shader::~Shader()
which, in turn, suggests that you are not defining the destructor for the Shader() class.