Skip to content

Commit

Permalink
Don't merge a layer if it's an entry layer (#1103)
Browse files Browse the repository at this point in the history
Don't merge a layer if it's an entry layer
Add test case for merging duplicate layers that are also entry layers.

Remove DASSERT that aborted entry layers being merged
  • Loading branch information
derekhaase authored and lgritz committed Jan 28, 2020
1 parent 3ae241a commit 7f8b7e3
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 3 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ TESTSUITE ( aastep allowconnect-err and-or-not-synonyms arithmetic
layers-nonlazycopy layers-repeatedoutputs
linearstep
logic loop matrix message
mergeinstances-duplicate-entrylayers
mergeinstances-nouserdata mergeinstances-vararray
metadata-braces miscmath missing-shader
noise noise-cell
Expand Down
3 changes: 2 additions & 1 deletion src/liboslexec/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ ShadingContext::execute_init (ShaderGroup &sgroup, ShaderGlobals &ssg, bool run)
bool
ShadingContext::execute_layer (ShaderGlobals &ssg, int layernumber)
{
DASSERT (group() && group()->nlayers() && !group()->does_nothing());
if (!group() || group()->nlayers() == 0 || group()->does_nothing())
return false;
DASSERT (ssg.context == this && ssg.renderer == renderer());

int profile = shadingsys().m_profile;
Expand Down
4 changes: 2 additions & 2 deletions src/liboslexec/shadingsys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2995,8 +2995,8 @@ ShadingSystemImpl::merge_instances (ShaderGroup &group, bool post_opt)

// Loop over all layers...
for (int a = 0; a < nlayers-1; ++a) {
if (group[a]->unused()) // Don't merge a layer that's not used
continue;
if (group[a]->unused() || group[a]->entry_layer()) // Don't merge a layer that's not used
continue; // or if it's an entry layer
// Check all later layers...
for (int b = a+1; b < nlayers; ++b) {
if (group[b]->unused()) // Don't merge a layer that's not used
Expand Down
12 changes: 12 additions & 0 deletions testsuite/mergeinstances-duplicate-entrylayers/a.osl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
shader a
(
float frequency = 1,
string noiseType = "perlin",
color amplitude = 1,
int seed = 0,
output color out = 0
)
{
point domain = point(u + seed, v + seed, 0) * frequency;
out = noise(noiseType, domain[0], domain[1]) * amplitude;
}
8 changes: 8 additions & 0 deletions testsuite/mergeinstances-duplicate-entrylayers/b.osl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
shader b
(
color in = 0,
output color out = 0
)
{
out = in;
}
4 changes: 4 additions & 0 deletions testsuite/mergeinstances-duplicate-entrylayers/ref/out.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Compiled a.osl -> a.oso
Compiled b.osl -> b.oso
Entry layers: b1(1) b2(3) b3(5)

4 changes: 4 additions & 0 deletions testsuite/mergeinstances-duplicate-entrylayers/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env python

command = testshade("--group data/shadergroup -O2 " +
"--entry b1 --entry b2 --entry b3")
11 changes: 11 additions & 0 deletions testsuite/mergeinstances-duplicate-entrylayers/shadergroup
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
shader a a1 ;
shader b b1 ;
connect a1.out b1.in ;

shader a a2 ;
shader b b2 ;
connect a2.out b2.in ;

shader a a3 ;
shader b b3 ;
connect a3.out b3.in ;

0 comments on commit 7f8b7e3

Please sign in to comment.