Skip to content

Commit

Permalink
fix: Don't try to ReParameter symbols not in the group (#1693)
Browse files Browse the repository at this point in the history
Sometimes, after optimization, symbols tagged as interactive
get removed because they are unused. But ReParameter is failing
with errors because it goes looking for the removed symbol to
master, which is, of course, not interactive. This patch avoids
that so the symbol is not found and we just return false.

Signed-off-by: Alejandro Conty <[email protected]>
  • Loading branch information
aconty authored Jun 9, 2023
1 parent b76a53a commit 4e9e640
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
10 changes: 6 additions & 4 deletions src/liboslexec/instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,19 @@ ShaderInstance::findsymbol(ustring name) const


int
ShaderInstance::findparam(ustring name) const
ShaderInstance::findparam(ustring name, bool search_master) const
{
if (m_instsymbols.size())
for (int i = m_firstparam, e = m_lastparam; i < e; ++i)
if (m_instsymbols[i].name() == name)
return i;

// Not found? Try the master.
for (int i = m_firstparam, e = m_lastparam; i < e; ++i)
if (master()->symbol(i)->name() == name)
return i;
if (search_master) {
for (int i = m_firstparam, e = m_lastparam; i < e; ++i)
if (master()->symbol(i)->name() == name)
return i;
}

return -1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/liboslexec/oslexec_pvt.h
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,7 @@ class ShaderInstance {

/// Find the named parameter, return its index in the symbol array, or
/// -1 if not found.
int findparam(ustring name) const;
int findparam(ustring name, bool search_master = true) const;

/// Return a pointer to the symbol (specified by integer index),
/// or NULL (if index was -1, as returned by 'findsymbol').
Expand Down
9 changes: 8 additions & 1 deletion src/liboslexec/shadingsys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3213,7 +3213,14 @@ ShadingSystemImpl::ReParameter(ShaderGroup& group, string_view layername_,
return false; // could not find the named layer

// Find the named parameter within the layer
int paramindex = layer->findparam(ustring(paramname));
int paramindex = layer->findparam(ustring(paramname),
false /* don't go to master */);
if (paramindex < 0) {
paramindex = layer->findparam(ustring(paramname), true);
if (paramindex >= 0)
// This param exists, but it got optimized away, no failure
return true;
}
if (paramindex < 0)
return false; // could not find the named parameter

Expand Down

0 comments on commit 4e9e640

Please sign in to comment.