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

Bug fix: assigning init-op param its default value as instance got lost #1578

Merged
merged 1 commit into from
Sep 12, 2022

Conversation

lgritz
Copy link
Collaborator

@lgritz lgritz commented Sep 10, 2022

This is a tricky situation to describe. Consider this shader:

shader test (float A = 0.5,
             float B = A)
{
    printf("A = %g, B = %g\n", A, B);
}

By default, A is 0.5 and B gets A's value, also 0.5. If you give A a different instance value, like 1.0, then B will also get the same value, they'll both be 1.0. If you give B an instance value, that will be used for B rather than copying A's value, like this:

$ testshade  -param B 1.0 -shader test test
A = 0.5, B = 1

But there is a corner case bug: if we assign B an instance value of 0.0, it will incorrectly fall into a special case where it thinks it gets a default value, only coincidentally because 0.0 is in an unused slot for the default value (unused because it has no default -- its default comes from "init ops", that assignment).

$ testshade  -param B 0.0 -shader test test
A = 0.5, B = 0.5

!!!

Reading the patch should be self-explanatory for what the bug is and how we fix it.

Signed-off-by: Larry Gritz lg@larrygritz.com

This is a tricky situation to describe. Consider this shader:

    shader test (float A = 0.5,
                 float B = A)
    {
        printf("A = %g, B = %g\n", A, B);
    }

By default, A is 0.5 and B gets A's value, also 0.5. If you give A a
different instance value, like 1.0, then B will also get the same
value, they'll both be 1.0.  If you give B an instance value, that
will be used for B rather than copying A's value, like this:

    $ testshade  -param B 1.0 -shader test test
    A = 0.5, B = 1

But there is a corner case bug: if we assign B an instance value of
0.0, it will incorrectly fall into a special case where it thinks it
gets a default value, only coincidentally because 0.0 is in an unused
slot for the default value (unused because it has no default -- its
default comes from "init ops", that assignment).

    $ testshade  -param B 0.0 -shader test test
    A = 0.5, B = 0.5

!!!

Reading the patch should be self-explanatory for what the bug is and
how we fix it.

Signed-off-by: Larry Gritz <lg@larrygritz.com>
@lgritz lgritz requested a review from lkerley September 10, 2022 23:42
@lgritz
Copy link
Collaborator Author

lgritz commented Sep 10, 2022

@lkerley @sandipshukla This is the weird bug we talked about a couple days ago.

@sandipshukla
Copy link
Contributor

sandipshukla commented Sep 11, 2022 via email

@lgritz lgritz merged commit c8dd33f into AcademySoftwareFoundation:main Sep 12, 2022
lgritz added a commit to lgritz/OpenShadingLanguage that referenced this pull request Sep 13, 2022
…st (AcademySoftwareFoundation#1578)

This is a tricky situation to describe. Consider this shader:

    shader test (float A = 0.5,
                 float B = A)
    {
        printf("A = %g, B = %g\n", A, B);
    }

By default, A is 0.5 and B gets A's value, also 0.5. If you give A a
different instance value, like 1.0, then B will also get the same
value, they'll both be 1.0.  If you give B an instance value, that
will be used for B rather than copying A's value, like this:

    $ testshade  -param B 1.0 -shader test test
    A = 0.5, B = 1

But there is a corner case bug: if we assign B an instance value of
0.0, it will incorrectly fall into a special case where it thinks it
gets a default value, only coincidentally because 0.0 is in an unused
slot for the default value (unused because it has no default -- its
default comes from "init ops", that assignment).

    $ testshade  -param B 0.0 -shader test test
    A = 0.5, B = 0.5

!!!

Reading the patch should be self-explanatory for what the bug is and
how we fix it.

Signed-off-by: Larry Gritz <lg@larrygritz.com>

Signed-off-by: Larry Gritz <lg@larrygritz.com>
@lgritz lgritz deleted the lg-param branch September 13, 2022 00:52
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

Successfully merging this pull request may close these issues.

None yet

3 participants