Skip to content

Commit c294cdd

Browse files
sfriedmapixarlgritz
authored andcommitted
Make isconnected() work with downstream renderer "connections." (#1782)
The isconnected() returns 2 when used on an output that is connected to another downstream shader node -- this can be used to limit computation to only the outputs used. However, that misses the important case of where the renderer has declared a shader node output as a renderer output, which happens often when using OSL purely for pattern generation purposes. This change makes that case also return 2. The isconnected test has been updated to include testing this functionality. Signed-off-by: Stephen Friedman <[email protected]>
1 parent 9176da3 commit c294cdd

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

src/liboslexec/runtimeoptimize.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2501,7 +2501,8 @@ RuntimeOptimizer::resolve_isconnected()
25012501
bool upconnected = s->connected();
25022502
if (s->interpolated() && shadingsys().userdata_isconnected())
25032503
upconnected = true;
2504-
int val = (upconnected ? 1 : 0) + (s->connected_down() ? 2 : 0);
2504+
bool downconnected = s->connected_down() || s->renderer_output();
2505+
int val = (upconnected ? 1 : 0) + (downconnected ? 2 : 0);
25052506
turn_into_assign(op, add_constant(TypeDesc::TypeInt, &val),
25062507
"resolve isconnected()");
25072508
}

testsuite/isconnected/ref/out.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ Compiled test.osl -> test.oso
22
Compiled upstream.osl -> upstream.oso
33
Connect upstream.out to downstream.a
44
Connect upstream.struct1 to downstream.mystruct1
5+
6+
Output Fout to out.tif
57
Upstream:
68
out connected: 2 (value=0.5)
79
notout connected: 0 (value=10)
@@ -22,7 +24,7 @@ mystruct1.y connected: 1 (value=4)
2224
mystruct2 connected: 0 (value={0, 0})
2325
mystruct2.x connected: 0 (value=0)
2426
mystruct2.y connected: 0 (value=0)
25-
27+
Fout connected: 2 (value=0.42)
2628
Connect upstream.out to downstream.a
2729
Connect upstream.struct1 to downstream.mystruct1
2830
Upstream:
@@ -45,4 +47,5 @@ mystruct1.y connected: 1 (value=4)
4547
mystruct2 connected: 0 (value={0, 0})
4648
mystruct2.x connected: 0 (value=0)
4749
mystruct2.y connected: 0 (value=0)
50+
Fout connected: 0 (value=0)
4851

testsuite/isconnected/run.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
# SPDX-License-Identifier: BSD-3-Clause
55
# https://github.com/AcademySoftwareFoundation/OpenShadingLanguage
66

7-
command = testshade("--layer upstream upstream --layer downstream test " +
7+
command = testshade("-g 1 1 -od uint8 -o Fout out.tif " +
8+
"--layer upstream upstream --layer downstream test " +
89
"--connect upstream out downstream a " +
9-
"--connect upstream struct1 downstream mystruct1")
10+
"--connect upstream struct1 downstream mystruct1"
11+
)
1012

1113
# Run again, this time considering userdata (lockgeom=0) parameters to be
1214
# isconnected(). This time, parameter c should look like a connection.

testsuite/isconnected/test.osl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
shader test (float a = 0, float b = 0,
88
float c = 0 [[ int lockgeom=0 ]],
99
MyStruct mystruct1 = {0,0},
10-
MyStruct mystruct2 = {0,0})
10+
MyStruct mystruct2 = {0,0},
11+
output float Fout = 1)
1112
{
1213
printf ("a=%g\n", a); // force retrieval/execution of upstream layer
1314
printf ("Downstream:\n");
@@ -16,4 +17,14 @@ shader test (float a = 0, float b = 0,
1617
status (c, "c");
1718
status (mystruct1, "mystruct1");
1819
status (mystruct2, "mystruct2");
20+
21+
if (isconnected(Fout) == 2)
22+
{
23+
Fout = .42;
24+
}
25+
else
26+
{
27+
Fout = 0;
28+
}
29+
status (Fout, "Fout");
1930
}

0 commit comments

Comments
 (0)