Adding standard derivatives extension leads to a compiled failure

Hi, guys.

I’m having a problem now. When I added “#extension GL_OES_standard_derivatives : enable” to my fragment shader code for using dFdx/dFdy such derivative function, I had a compiler error message: Unexpected extension directive encountered after non-preprocessor tokens.

However, if I remove the extension line, the derivative function can be used successfully. But if I want to run on the other non-powervr simulator (lower ES-SL version), I still need that extension line.

What I don’t get it is, if the extension derivative function is already supported for ES-SL 3.0 with powervr, why would we have an compiled error while adding that extension line? Is there any possible way to make that extension line work without getting compiled error? Otherwise I have to write two shader code, one for PowerVR, one for the other…

P.S The attachments is my OpenGL ES information by using PVRVFrame (from PowerVR SDK 3.5).

[attachment file=“51782”]

Hi Chester,

This sounds like a bug in our emulator. I’ll discuss the issue with the PVRVFrame lead.

Is the issue only reproducible with PVRVFrame emulation or does it also occur on PowerVR devices?

Hi Chester,

I’ve discussed the “Unexpected extension directive encountered after non-preprocessor tokens.” error with the PVRVFrame lead. He’s informed me that this is a requirement of the GLSL ES 1.00 spec. On page 15 of the GLSL ES 1.0.17 specification, it states.

[blockquote]extension directives must occur before any non-preprocessor tokens.[/blockquote]

What this means is that it is illegal to define non-preprocessor tokens, such as variable and functions, before extension directives. If you move “#extension GL_OES_standard_derivatives : enable” to the start of your shader, it should compile correctly in PVRVFrame and all other GLSL ES compilers.

Hi, Joe:

Thanks for your quick response :slight_smile:

I did move that line to the start of my shader code before, however somehow it still didn’t work.

Hi Chester,

Do you mean that, even with moving the declaration to the start of the shader, you are still encountering the issue?

For reference this shader should generate an error according to the GLSL ES 1.00 specification:

[pre]#version 100
uniform mediump vec4 colour;
#extension GL_OES_standard_derivatives : enable
void main[] {
gl_FragColor = colour;
}[/pre]

This modified version should compile correctly with all conformant GLSL ES 1.00 compilers:

[pre]#version 100
#extension GL_OES_standard_derivatives : enable
uniform mediump vec4 colour;
void main[] {
gl_FragColor = colour;
}[/pre]

Our PVRShaderEditor tool gives as-you-type errors, warnings and performance estimates. If you are not using it already, I would recommend giving it a go. The shader verification code used by PVRShaderEditor is also used by PVRVFrame, so the errors should be the same in both tools.

Here is first three lines from my fragment shader code:

#version 100 // With or without this line doesn’t affect the error.
#extension GL_OES_standard_derivatives : enable // Move this line above everything.
precision mediump float;

By using the PVRShaderEditor tool, it said ‘Compile succeeded’. However, when I run my program via visual studio 2010, the shader code can not be built successfully. The error I got is shown in following:

Vertex shader[s] failed to link, fragment shader[s] failed to link.
Vertex link error: INVALID_OPERATION.
ERROR: error[#97] No program main found
fragment link error: INVALID_OPERATION.
ERROR: error[#97] No program main found
ERROR: Failed to create OpenGL programs
ERROR: Failed to init ResourceTracker

I didn’t see this error on the other non-powervr simulator with the same code.

Hi Chester,

I’m discussing the issue with the PVRVFrame lead now. If you can share a reproduction binary with us, it should help speed up our investigation. You can share packages with us confidentially through our ticketing system: https://pvrsupport.imgtec.com/new-ticket

Hi Chester,

The PVRVFrame lead has told me that, from the errors alone, he can’t determine what’s causing the problem. If you can provide a reproduction binary we’ll continue our investigation.