From 4e9e640e5bc0d26392759beb0a8525120acda071 Mon Sep 17 00:00:00 2001 From: Alejandro Conty Date: Fri, 9 Jun 2023 19:34:13 +0200 Subject: [PATCH] fix: Don't try to ReParameter symbols not in the group (#1693) 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 --- src/liboslexec/instance.cpp | 10 ++++++---- src/liboslexec/oslexec_pvt.h | 2 +- src/liboslexec/shadingsys.cpp | 9 ++++++++- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/liboslexec/instance.cpp b/src/liboslexec/instance.cpp index d7bb90dc8..dfcf3cdbe 100644 --- a/src/liboslexec/instance.cpp +++ b/src/liboslexec/instance.cpp @@ -109,7 +109,7 @@ 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) @@ -117,9 +117,11 @@ ShaderInstance::findparam(ustring name) const 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; } diff --git a/src/liboslexec/oslexec_pvt.h b/src/liboslexec/oslexec_pvt.h index c4f27f57d..deeed54c2 100644 --- a/src/liboslexec/oslexec_pvt.h +++ b/src/liboslexec/oslexec_pvt.h @@ -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'). diff --git a/src/liboslexec/shadingsys.cpp b/src/liboslexec/shadingsys.cpp index 81e75e354..5a09d9443 100644 --- a/src/liboslexec/shadingsys.cpp +++ b/src/liboslexec/shadingsys.cpp @@ -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