Skip to content

Commit c2ce3cd

Browse files
chellmuthlgritz
authored andcommitted
fix: error when an interactive param is also connected (#2121)
When a parameter is interactive and connected, the connection should win. OSL was incorrectly treating the interactive trait as taking precedence, attempting to write into the read-only interactive buffer during shader execution. Fixed both single point and batch modes. --------- Signed-off-by: Chris Hellmuth <chellmuth@gmail.com>
1 parent be3406e commit c2ce3cd

8 files changed

Lines changed: 52 additions & 3 deletions

File tree

src/cmake/testing.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ macro (osl_add_all_tests)
356356
printf-reg
357357
printf-whole-array
358358
raytype raytype-reg raytype-specialized regex-reg
359-
reparam reparam-arrays reparam-string testoptix-reparam
359+
reparam reparam-arrays reparam-connected-crash reparam-string testoptix-reparam
360360
render-background render-bumptest
361361
render-bunny
362362
render-cornell

src/liboslexec/backendllvm.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@ BackendLLVM::getLLVMSymbolBase(const Symbol& sym)
232232
llvm_type(sym.typespec().elementtype()));
233233
return result;
234234
}
235-
if (sym.symtype() == SymTypeParam && sym.interactive()) {
235+
if (sym.symtype() == SymTypeParam && sym.interactive()
236+
&& !sym.connected()) {
236237
// Special case for interactively-edited parameters -- they live in
237238
// the interactive data block for the group.
238239
// Generate the pointer to this symbol by offsetting into the

src/liboslexec/batched_backendllvm.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,8 @@ BatchedBackendLLVM::getLLVMSymbolBase(const Symbol& sym)
454454
return result;
455455
}
456456

457-
if (sym.symtype() == SymTypeParam && sym.interactive()) {
457+
if (sym.symtype() == SymTypeParam && sym.interactive()
458+
&& !sym.connected()) {
458459
// Special case for interactively-edited parameters -- they live in
459460
// the interactive data block for the group.
460461
// Generate the pointer to this symbol by offsetting into the

testsuite/reparam-connected-crash/BATCHED

Whitespace-only changes.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright Contributors to the Open Shading Language project.
2+
// SPDX-License-Identifier: BSD-3-Clause
3+
// https://github.com/AcademySoftwareFoundation/OpenShadingLanguage
4+
5+
// Downstream layer: 'in' will be marked interactive with an instance value
6+
// via testshade -param:interactive=1
7+
shader downstream(float in = 0, output float result = 0)
8+
{
9+
printf("in = %g\n", in);
10+
result = in;
11+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Compiled downstream.osl -> downstream.oso
2+
Compiled upstream.osl -> upstream.oso
3+
Connect upstream_layer.out to downstream_layer.in
4+
in = 0.5
5+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright Contributors to the Open Shading Language project.
4+
# SPDX-License-Identifier: BSD-3-Clause
5+
# https://github.com/AcademySoftwareFoundation/OpenShadingLanguage
6+
7+
# Regression test: downstream input param is both connected (from upstream) and
8+
# marked interactive with an instance value.
9+
#
10+
# Bug: OSL give precedence to the interactive trait instead of connected. This
11+
# leads to an attempted write of the interactive buffer. However, the offset
12+
# is calculated incorrectly and the write occurs at interactive_buffer[-1].
13+
#
14+
# Correct output: in = 0.5 (u at the default shade point, from the connection)
15+
# Buggy output: in = <garbage> (corrupted memory) or crash
16+
17+
command += testshade(
18+
"-layer upstream_layer upstream "
19+
"-layer downstream_layer -param:interactive=1 in 9.0 downstream "
20+
"-connect upstream_layer out downstream_layer in "
21+
)
22+
23+
outputs = ["out.txt"]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright Contributors to the Open Shading Language project.
2+
// SPDX-License-Identifier: BSD-3-Clause
3+
// https://github.com/AcademySoftwareFoundation/OpenShadingLanguage
4+
5+
shader upstream(output float out = 0)
6+
{
7+
out = u; // don't constant-fold
8+
}

0 commit comments

Comments
 (0)