GLSL 4.2 - Syntax error: "layout" parse error - opengl

So, I recently found an interesting shader and tried to compile it.
But, the GLSL compiler threw the following error:
ERROR: 0:50: error(#132) Syntax error: "layout" parse error
# (Fragment shader)
#version 420
...
uint ImageAtomic_Average_RGBA8(layout (r32ui) volatile uimage3D Img, ivec3 Coords, vec4 NewVal)
{ ... }
Details:
Card: AMD Radeon HD 7870 (It supports OpenGL 4.20)
I tried both the 4.2 driver and the 4.3 beta driver.

A layout qualifier cannot be part of the function's signature. Section 6.1.1 of the GLSL 4.40 Specification defines the following grammar for a function prototype:
function-prototype :
precision-qualifier type function-name(*parameter-qualifiers* precision-qualifier type name array-specifier, ... )
Now, a parameter-qualifier can be one of
const
in
out
inout
precise
memory qualifier (volatile, ...)
precision qualifier(lowp, ...)
Consistently, section 4.10 explicitly states:
Layout qualifiers cannot be used on formal function parameters [..]
If you drop the layout qualifier, you should be fine. If not, it's a driver bug.

Related

how do I solve the error of loop in webgl shader

When I pass in an uniform int variable for a for loop, it reports an error
When I define a constant, it doesn't report an error,
How to solve it
// error INVALID_OPERATION
uniform int myLen;
for (int i = 0; i < myLen; i += 1)
// success
const int myNum = 10;
for (int i = 0; i < myNum; i += 1)
I am guessing you are targeting WebGL 1.
If we look at the specification for The OpenGL® ES Shading Language, version 1.00, which is what WebGL uses, and look at the section "Appendix A: Limitations for ES 2.0" (OpenGL ES 2.0 is what WebGL 1 is based on), it says:
In general, control flow is limited to forward branching and to loops where the maximum number of
iterations can easily be determined at compile time.
[…]
for loops are supported but with the following restrictions:
[…]
The for statement has the form:
for ( init-declaration ; condition ; expression ) statement
[…]
condition has the form
loop_index relational_operator constant_expression
where relational_operator is one of: > >= < <= == or !=
Note the "constant_expression". This unfortunately means that you aren't allowed* to use a uniform variable for your loop bound, like you did.
I believe this is different in WebGL 2. You might want to try using that if it's an option.
* The GLSL ES spec does say "Within the GLSL ES specification, implementations are permitted to implement features beyond the minima described in this section, without the use of an extension." However, unfortunately WebGL's specification prohibits this:
A WebGL implementation must only accept shaders which conform to The OpenGL ES Shading Language, Version 1.00 [GLES20GLSL], and which do not exceed the minimum functionality mandated in Sections 4 and 5 of Appendix A

Enable extension and fwidth in glsl

I'm using webGL and I want to use fwidth as I did it in Three.js.
in .glsl file I've added an extension like this:
#ifndef GL_ES
// Non OpenGL ES devices doesnt support precision qualifiers, so we do
// nothing instead
#define lowp
#define mediump
#define highp
#else
// to have functions like fwidth for OpenGL ES or WebGL, the extension should
// be explicitly enabled.
#extension GL_OES_standard_derivatives : enable
#endif
But I'm keep getting this errors:
Error compiling FRAGMENT_SHADER: WARNING: 0:14: '
' : extension directive should occur before any non-preprocessor tokens
WARNING: 0:14: 'GL_OES_standard_derivatives' : extension is not supported
ERROR: 0:47: 'fwidth' : no matching overloaded function found
If anyone knows how to fix this - would be great to get a hint.

Validation failure tex2D HLSL Shader Model 6.0

So apparently tex2D is still supported in HLSL shaderModel 6.0 so why does doing something like the following produce validation errors:
float myFloat = tex2D(MySampler, In.texCoord).w;
It does not like tex2D, if I make a Texture2D MyTex variable 1st then do
MyFloat = MyTex.Sample(MySampler, In.texCoord).w; validation is fine.
Of course I have disables validation with /Vd and dxc spits out a compiled file but no .asm when specified, dxc also tends to jam up with tex2D usage....
I have tried compilation with multiple versions of dxc.exe
Any ideas?
Thanks

imageAtomicExchange won't compile

I'm trying to use two opengl images, one of which is sparse and the other used as a sort of page table, in which I keep track of the page actually commited.
I have a simple little shader, which looks like this (main not included):
#version 450 core
#extension GL_ARB_shader_image_load_store : require
uniform float gridSize;
uniform float pageTableSize;
bool isPageInMemoryOrRequest (in ivec3 pos)
{
bool returnValue = false;
if ( 255u == imageAtomicExchange(pageTable, pos, 128u) )
{
returnValue = true;
}
return returnValue;
}
And my problem is that this won't compile. I keep getting this message:
Error C1115: unable to find compatible overloaded function "imageAtomicExchange(struct uimage3D1x8_bindless, ivec3, uint)"
I'm pretty sure I've never seen that _bindless part anywhere in the specs and I'm not exactly sure how the compiler figures out that is a bindless texture at compile time (or maybe they're all bindless in the latest drivers).
I've got a GTX660TI and I'm using the 352.86 drivers.
I'm wondering if anyone's had this sort of issue before and could tell me what might the problem be.
Thanks in advance.
According to the extension specification of ARB_shader_image_load_store (Section 8.X, Image Functions), there is only of very limited number of supported formats for atomic operations:
Atomic memory operations
are supported on only a subset of all image variable types; must
be either:
an image variable with signed integer components (iimage*) and a
format qualifier of "r32i", or
an image variable with unsigned integer components (uimage*) and a
format qualifier of "r32ui".
I assume from the error message, that you have tried to use a r8ui format, which is not supported.

"invalid operation" on shader loading and compiling

Problem
Having a shader program in a.vs as:
#version 330
in vec2 vPosition;
void main() {
gl_Position = vec4(vPosition, 0.0, 1.0);
}
and given:
import qualified Graphics.GLUtil as GLU
import qualified Graphics.Rendering.OpenGL as GL
this line:
vs <- GLU.loadShader GL.VertexShader $ shaderPath </> "a.vs"
causes:
GL: Error InvalidOperation "invalid operation"
at runtime.
Details
I'm running on Mac OS X 10.10.2. The OpenGL context is set via GLFW with:
GLFW.windowHint $ GLFW.WindowHint'OpenGLDebugContext True
GLFW.windowHint $ GLFW.WindowHint'ContextVersionMajor 3
GLFW.windowHint $ GLFW.WindowHint'ContextVersionMinor 3
GLFW.windowHint $ GLFW.WindowHint'OpenGLForwardCompat True
GLFW.windowHint $ GLFW.WindowHint'OpenGLProfile GLFW.OpenGLProfile'Core
giving an OpenGL 3.3 context.
The context of the code can be found at this repository (link to the specific commit), and specifically in Main.hs.
Question
What can I do to fix this issue or get more debugging informations?
I ran your code under gDebugger, and it made it plain:
GL.matrixMode $= GL.Projection
GL.loadIdentity
GL.ortho2D 0 (realToFrac w) (realToFrac h) 0
This leftover piece of code was triggering an error state:
Error-Code: GL_INVALID_OPERATION
Error-Description:
The specified operation is not allowed in the current state. The offending function is ignored, having no side effect other than to set the error flag.
As a side note, shader compilation can never trigger an INVALID_OPERATION (except when you try to render with a broken pipeline); the compilation errors can be obtained by checking the compilation status directly.