Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate symbol derivatives for outputs when requested #1916

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/liboslexec/batched_analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2175,11 +2175,8 @@ struct Analyzer {
const SymLocationDesc* symloc = nullptr;
if (interpolate_param) {
// See if userdata input placement has been used for this symbol
ustring layersym = ustring::fmtformat("{}.{}", inst()->layername(),
s.name());
symloc = m_ba.group().find_symloc(layersym, SymArena::UserData);
if (!symloc)
symloc = m_ba.group().find_symloc(s.name(), SymArena::UserData);
symloc = m_ba.group().find_symloc(s.name(), inst()->layername(),
SymArena::UserData);
if (symloc != nullptr) {
// We copy values from userdata pre-placement which always succeeds
// We must track this write, not because it will need to be masked
Expand Down
16 changes: 4 additions & 12 deletions src/liboslexec/batched_llvm_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1190,11 +1190,8 @@ BatchedBackendLLVM::llvm_assign_initial_value(

llvm::Value* got_userdata = nullptr;
// See if userdata input placement has been used for this symbol
ustring layersym = ustring::fmtformat("{}.{}", inst()->layername(),
sym.name());
symloc = group().find_symloc(layersym, SymArena::UserData);
if (!symloc)
symloc = group().find_symloc(sym.name(), SymArena::UserData);
symloc = group().find_symloc(sym.name(), inst()->layername(),
SymArena::UserData);
if (symloc) {
// We had a userdata pre-placement record for this variable.
// Just copy from the correct offset location!
Expand Down Expand Up @@ -2361,13 +2358,8 @@ BatchedBackendLLVM::build_llvm_instance(bool groupentry)
{
if (!s.renderer_output()) // Skip if not a renderer output
continue;
// Try to look up the sym among the outputs with the full layer.name
// specification first. If that fails, look for name only.
ustring layersym = ustring::fmtformat("{}.{}", inst()->layername(),
s.name());
auto symloc = group().find_symloc(layersym, SymArena::Outputs);
if (!symloc)
symloc = group().find_symloc(s.name(), SymArena::Outputs);
auto symloc = group().find_symloc(s.name(), inst()->layername(),
SymArena::Outputs);
if (!symloc) {
// std::cout << "No output copy for " << s.name()
// << " because no symloc was found\n";
Expand Down
16 changes: 4 additions & 12 deletions src/liboslexec/llvm_instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -818,11 +818,8 @@ BackendLLVM::llvm_assign_initial_value(const Symbol& sym, bool force)
llvm::Value* got_userdata = nullptr;

// See if userdata input placement has been used for this symbol
ustring layersym = ustring::fmtformat("{}.{}", inst()->layername(),
sym.name());
symloc = group().find_symloc(layersym, SymArena::UserData);
if (!symloc)
symloc = group().find_symloc(sym.name(), SymArena::UserData);
symloc = group().find_symloc(sym.name(), inst()->layername(),
SymArena::UserData);
if (symloc) {
// We had a userdata pre-placement record for this variable.
// Just copy from the correct offset location!
Expand Down Expand Up @@ -1793,13 +1790,8 @@ BackendLLVM::build_llvm_instance(bool groupentry)
{
if (!s.renderer_output()) // Skip if not a renderer output
continue;
// Try to look up the sym among the outputs with the full layer.name
// specification first. If that fails, look for name only.
ustring layersym = ustring::fmtformat("{}.{}", inst()->layername(),
s.name());
auto symloc = group().find_symloc(layersym, SymArena::Outputs);
if (!symloc)
symloc = group().find_symloc(s.name(), SymArena::Outputs);
auto symloc = group().find_symloc(s.name(), inst()->layername(),
SymArena::Outputs);
if (!symloc) {
// std::cout << "No output copy for " << s.name()
// << " because no symloc was found\n";
Expand Down
15 changes: 15 additions & 0 deletions src/liboslexec/oslexec_pvt.h
Original file line number Diff line number Diff line change
Expand Up @@ -1931,6 +1931,21 @@ class ShaderGroup {
return nullptr;
}

// Find the SymLocationDesc for this named param but only if it matches
// the arena type, returning its pointer or nullptr if that name is not
// found.
// Try to look up the sym with the full layer.name specification first.
// If that fails, try again based on name only.
const SymLocationDesc* find_symloc(ustring name, ustring layer,
SymArena arena) const
{
ustring layersym = ustring::fmtformat("{}.{}", layer, name);
auto symloc = find_symloc(layersym, arena);
if (!symloc)
symloc = find_symloc(name, arena);
return symloc;
}

// Given a data block for interactive params, allocate space for it to
// live with the group and copy the initial data.
void setup_interactive_arena(cspan<uint8_t> paramblock);
Expand Down
9 changes: 9 additions & 0 deletions src/liboslexec/runtimeoptimize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2698,6 +2698,15 @@ RuntimeOptimizer::track_variable_dependencies()
if (s.symtype() == SymTypeGlobal && s.everwritten()
&& !s.typespec().is_closure_based() && s.mangled() != Strings::N)
s.has_derivs(true);
// If the renderer requests a symbol to be written as an output with
// derivs, mark them to be generated.
if (s.renderer_output()) {
auto symloc = group().find_symloc(s.name(), inst()->layername(),
SymArena::Outputs);
if (symloc && symloc->derivs && s.everwritten()
&& !s.typespec().is_closure_based())
s.has_derivs(true);
}
if (s.has_derivs())
add_dependency(symdeps, DerivSym, snum);
++snum;
Expand Down
Loading