Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shaders::MeshVisualizer fails to compile on ANGLE #56

Closed
mosra opened this issue May 20, 2014 · 1 comment
Closed

Shaders::MeshVisualizer fails to compile on ANGLE #56

mosra opened this issue May 20, 2014 · 1 comment

Comments

@mosra
Copy link
Owner

mosra commented May 20, 2014

As reported in mosra/kotel#1, the ANGLE GLSL-to-HLSL converter fails to compile the shader because of non-constant vector component indexing in src/Magnum/Shaders/MeshVisualizer.vert:

AbstractShaderProgram::link(): linking failed with the following message: 
(26,2-71): error X3500: array reference cannot be used as an l-value; not natively addressable 
Warning: D3D shader compilation failed with default flags. 
Failed to create D3D shaders. 
Assertion link() failed in ../src/Magnum/Shaders/MeshVisualizer.cpp on line 107 

The offending line is:

barycentric[int(mod(vertexIndex, 3.0))] = 1.0;

GLSL ES 1.0 specification allows this (section 5.5), so it should be supported in ANGLE too:

Array subscripting syntax can also be applied to vectors to provide numeric indexing. So in

vec4 pos;

pos[2] refers to the third element of pos and is equivalent to pos.z. This allows variable indexing into a vector, as well as a generic way of accessing components. Any integer expression can be used as the subscript. The first component is at index zero. Reading from or writing to a vector using a constant integral expression with a value that is negative or greater than or equal to the size of the vector is illegal. When indexing with non-constant expressions, behavior is undefined if the index is negative or greater than or equal to the size of the vector.

Proposed solution is to work around this using ugly branch, but that might harm performance elsewhere.

int i = int(mod(vertexIndex, 3.0));
     if(i == 0) barycentric.x = 1.0;
else if(i == 1) barycentric.y = 1.0;
else            barycentric.z = 1.0;

Better (and future proof) solution would be to implement some ANGLE autodetection and enable this only if we might be running on ANGLE. Sadly there doesn't seem to be any easy way to do it.

@mosra
Copy link
Owner Author

mosra commented Jun 29, 2014

Apparently this restriction exists also on WebGL. Should be fixed for both WebGL and ANGLE in 4a44d3b.

@mosra mosra closed this as completed Jun 29, 2014
@mosra mosra added the bug label Jul 22, 2014
@mosra mosra modified the milestones: 2015.05, 2014.06 Feb 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant