Jump to content
  • Advertisement
Sign in to follow this  
kloffy

GLSL - Strange behavior with "inout" parameter - Bug?

This topic is 1050 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is the following fragment shader valid GLSL code? (This is a somewhat artificial example to illustrate the problem.)
[source=cpp]
#version 440 core

out vec4 frag_color;

void set_value(inout mat4[1] m, int i, int j, int k, float value)
{
m[j][k] = value;
}

void main()
{
mat4[1] color;
set_value(color, 0, 0, 0, 0.5);
set_value(color, 0, 0, 1, 0.5);
set_value(color, 0, 1, 0, 0.5);
set_value(color, 0, 1, 1, 1.0);
frag_color = vec4(color[0][0][0], color[0][0][1], color[0][1][0], color[0][1][1]);
}
[/source]
I would expect a gray fragment, but instead I get what seemingly random/flashing colors. I think the problem is the mat4 array inout parameter. Possibly a driver bug?

Share this post


Link to post
Share on other sites
Advertisement
[source=cpp]
#version 440 core

out vec4 frag_color;

float get(vec4 v, int i, int j) { return v[j]; }
float get(vec4[1] v, int i, int j) { return v[j]; }
float get(mat2 m, int i, int j, int k) { return m[j][k]; }
float get(mat2[1] m, int i, int j, int k) { return m[j][k]; }

void set(inout vec4 v, int i, int j, float value) { v[j] = value; }
void set(inout vec4[1] v, int i, int j, float value) { v[j] = value; }
void set(inout mat2 m, int i, int j, int k, float value) { m[j][k] = value; }
void set(inout mat2[1] m, int i, int j, int k, float value) { m[j][k] = value; }

void main()
{
#if 0
// Success
vec4 color;
set(color, 0, 0, 0.5);
set(color, 0, 1, 0.5);
set(color, 0, 2, 0.5);
set(color, 0, 3, 1.0);
frag_color = vec4(get(color, 0, 0), get(color, 0, 1), get(color, 0, 2), get(color, 0, 3));
#else
// Failure
mat2 color;
set(color, 0, 0, 0, 0.5);
set(color, 0, 0, 1, 0.5);
set(color, 0, 1, 0, 0.5);
set(color, 0, 1, 1, 1.0);
frag_color = vec4(get(color, 0, 0, 0), get(color, 0, 0, 1), get(color, 0, 1, 0), get(color, 0, 1, 1));
#endif
}
[/source]
Ok, I have updated my drivers and extended my test code and either I am missing something blindingly obvious, or matrices do not work as inout parameters. Edited by kloffy

Share this post


Link to post
Share on other sites
You did not fully initialize the matrix. Getting random junk should be expected, or—more likely—it should not compile.


L. Spiro

Share this post


Link to post
Share on other sites

You did not fully initialize the matrix. Getting random junk should be expected, or—more likely—it should not compile.

Are you sure? I am setting all of its values. Regardless, even if I initialize the matrix, I do not get the expected gray color.

[source=cpp]
mat2 color = mat2(1.0);
set(color, 0, 0, 0, 0.5);
set(color, 0, 0, 1, 0.5);
set(color, 0, 1, 0, 0.5);
set(color, 0, 1, 1, 1.0);
frag_color = vec4(get(color, 0, 0, 0), get(color, 0, 0, 1), get(color, 0, 1, 0), get(color, 0, 1, 1));
[/source]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!