AcademySoftwareFoundation / AcademySoftwareFoundation/OpenColorIO

OSL secondary functions can cause name clashes

Open
#1,851 0 comments 0 reactions 0 assignees View on GitHub
Needs Discussion
Dominant language
C++
Stars
2.1k
Forks
503
PR merge metrics
No merged PRs in 30d

Description

When generating OSL some secondary functions are introduced which don't seem to be considered when setting the option to try and generate unique function names. The following is an example generated:
```c++
/* All the includes */

#include "vector4.h"
#include "color4.h"

/* All the generic helper methods */

vector4 __operator__mul__(matrix m, vector4 v)
{
return vector4(v.x * m[0][0] + v.y * m[0][1] + v.z * m[0][2] + v.w * m[0][3],
v.x * m[1][0] + v.y * m[1][1] + v.z * m[1][2] + v.w * m[1][3],
v.x * m[2][0] + v.y * m[2][1] + v.z * m[2][2] + v.w * m[2][3],
v.x * m[3][0] + v.y * m[3][1] + v.z * m[3][2] + v.w * m[3][3]);
}

vector4 __operator__mul__(color4 c, vector4 v)
{
return vector4(c.rgb.r, c.rgb.g, c.rgb.b, c.a) * v;
}

vector4 __operator__mul__(vector4 v, color4 c)
{
return v * vector4(c.rgb.r, c.rgb.g, c.rgb.b, c.a);
}

vector4 __operator__sub__(color4 c, vector4 v)
{
return vector4(c.rgb.r, c.rgb.g, c.rgb.b, c.a) - v;
}

vector4 __operator__add__(vector4 v, color4 c)
{
return v + vector4(c.rgb.r, c.rgb.g, c.rgb.b, c.a);
}

vector4 __operator__add__(color4 c, vector4 v)
{
return vector4(c.rgb.r, c.rgb.g, c.rgb.b, c.a) + v;
}

vector4 pow(color4 c, vector4 v)
{
return pow(vector4(c.rgb.r, c.rgb.g, c.rgb.b, c.a), v);
}

vector4 max(vector4 v, color4 c)
{
return max(v, vector4(c.rgb.r, c.rgb.g, c.rgb.b, c.a));
}

/* The shader implementation */

shader OSL_mx_acescg_to_lin_rec709_color4(color4 inColor = {color(0), 1}, output color4 outColor = {color(0), 1})
{

// Declaration of the OCIO shader function

color4 mx_acescg_to_lin_rec709_color4(color4 inPixel)
{
color4 outColor = inPixel;

// Add Matrix processing

{
vector4 res = vector4(outColor.rgb.r, outColor.rgb.g, outColor.rgb.b, outColor.a);
vector4 tmp = res;
res = matrix(1.7050509926579815, -0.62179212065700562, -0.0832588720009797, 0., -0.1302564175070435, 1.1408047365754048, -0.010548319068357653, 0., -0.024003356804618042, -0.1289689760649709, 1.1529723328695858, 0., 0., 0., 0., 1.) * tmp;
outColor.rgb = vector(res.x, res.y, res.z);
outColor.a = res.w;
}

return outColor;
}

outColor = mx_acescg_to_lin_rec709_color4(inColor);
}
```
Some of the shader functions have been overridden but functions with generic names like `max()`. `pow()` and names like `__operator__add__` as well as include declarations means there can be name clashes and multiple identical includes when trying to insert more than one transform function into a larger OSL shader.

It is possible to post rename them, but wondering if there is a way to handle this so it's either reusable (allow for a seperate "common" source code" API access, or make the renaming logic also rename these functions.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.