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

Allow list initializer as function argument. #1906

Open
ld-kerley opened this issue Dec 5, 2024 · 1 comment
Open

Allow list initializer as function argument. #1906

ld-kerley opened this issue Dec 5, 2024 · 1 comment

Comments

@ld-kerley
Copy link

Problem

Initializer lists are not allowed as function arguments, would be nice if they were, and would possibly simplify some of the MaterialX code base for OSL code generation.

struct vector2
{
    float x;
    float y;
};

void NG_switch_vector2I(vector2 in1, vector2 in2, vector2 in3, output vector2 out)
{
    out = in1;
}

shader test_shader
(
    vector2 input = {1,2},              // this works
    output float out = 0
)
{
    vector2 outVec;
    vector2 in1 = {0,1};                // this works

    NG_switch_vector2I(
        in1,                            // this works
        vector2(0.000000, 0.000000),    // this works
        {0.000000, 0.000000},           // this doesn't work
        outVec);

    out = outVec.x;
}

Expected behavior:
I expected this to compile just fine...

Actual behavior:
But it didn't... I get the following compile error.

 > oslc test.osl
test.osl:24: error: Cannot construct type 'unknown'
FAILED test.osl

Steps to Reproduce

  1. Compile the shader code above
  2. Get compile error

Versions

  • OSL branch/version: 1.13.8.0
  • OS: MacOS Sequoia
  • C++ compiler:
  • LLVM version: 17.0.6
  • OIIO version: 2.5.9.0
@ld-kerley
Copy link
Author

Another potentially similar case where list initializer doesn't appear to be valid when assigning to an existing variable, but can be used when the variable is created.

two versions of mx_elementAt function below, one works if I create an intermediate object, but direct assignment to the output variable reports a syntax error.

struct A { 
    string aa; 
    string bb; 
};

struct B { 
    string cc[100]; 
    string dd; 
};

// doesn't work
void mx_elementAt(B in, int index, output A out)
{
    out = { in.cc[index], in.dd };
}

// works
// void mx_elementAt(B in, int index, output A out)
// {
//     A tmp = { in.cc[index], in.dd };
//     out = tmp;
// }

shader test
(
            B       in      = {{""}, ""},
            int     index   = 0,
    output  A       out     = {"", ""}
)
{
    A  a = A ("", "");
    mx_elementAt(in, index, a);
    out = a;
}

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

1 participant