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

global variable used in functions will be converted to parameters in metal shaders, sometimes resulting in parameters passed in wrong order. #30

Open
mattiasljungstrom opened this issue Jan 14, 2020 · 1 comment

Comments

@mattiasljungstrom
Copy link
Contributor

This isn't a major issue, but something I noticed and figured it's worth documenting. No error is shown, instead you get corrupted results during rendering.

Example code (bad):

sampler2D texture;

vec4 calc_something(vec2 uv, float scale)
{
    vec4 color = texture(texture, uv) * scale;
    return color;
}

The generated shader code on metal will add the sampler as an argument on the end of the calc_something() function, but will call it with the sampler as the first argument...

The issue can be avoided by passing in all parameters in the code, like this:

sampler2D texture;

vec4 calc_something(sampler2D tex, vec2 uv, float scale)
{
    vec4 color = texture(tex, uv) * scale;
    return color;
}
@floooh
Copy link
Owner

floooh commented Jan 14, 2020

Hmm, that's annoying :) Strange that it doesn't generate an error though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants