Skip to content

Commit 016a468

Browse files
Generate symbol derivatives for outputs when requested (#1916)
Signed-off-by: Lukas Stockner <[email protected]>
1 parent 71dd759 commit 016a468

File tree

5 files changed

+34
-29
lines changed

5 files changed

+34
-29
lines changed

src/liboslexec/batched_analysis.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2175,11 +2175,8 @@ struct Analyzer {
21752175
const SymLocationDesc* symloc = nullptr;
21762176
if (interpolate_param) {
21772177
// See if userdata input placement has been used for this symbol
2178-
ustring layersym = ustring::fmtformat("{}.{}", inst()->layername(),
2179-
s.name());
2180-
symloc = m_ba.group().find_symloc(layersym, SymArena::UserData);
2181-
if (!symloc)
2182-
symloc = m_ba.group().find_symloc(s.name(), SymArena::UserData);
2178+
symloc = m_ba.group().find_symloc(s.name(), inst()->layername(),
2179+
SymArena::UserData);
21832180
if (symloc != nullptr) {
21842181
// We copy values from userdata pre-placement which always succeeds
21852182
// We must track this write, not because it will need to be masked

src/liboslexec/batched_llvm_instance.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,11 +1190,8 @@ BatchedBackendLLVM::llvm_assign_initial_value(
11901190

11911191
llvm::Value* got_userdata = nullptr;
11921192
// See if userdata input placement has been used for this symbol
1193-
ustring layersym = ustring::fmtformat("{}.{}", inst()->layername(),
1194-
sym.name());
1195-
symloc = group().find_symloc(layersym, SymArena::UserData);
1196-
if (!symloc)
1197-
symloc = group().find_symloc(sym.name(), SymArena::UserData);
1193+
symloc = group().find_symloc(sym.name(), inst()->layername(),
1194+
SymArena::UserData);
11981195
if (symloc) {
11991196
// We had a userdata pre-placement record for this variable.
12001197
// Just copy from the correct offset location!
@@ -2361,13 +2358,8 @@ BatchedBackendLLVM::build_llvm_instance(bool groupentry)
23612358
{
23622359
if (!s.renderer_output()) // Skip if not a renderer output
23632360
continue;
2364-
// Try to look up the sym among the outputs with the full layer.name
2365-
// specification first. If that fails, look for name only.
2366-
ustring layersym = ustring::fmtformat("{}.{}", inst()->layername(),
2367-
s.name());
2368-
auto symloc = group().find_symloc(layersym, SymArena::Outputs);
2369-
if (!symloc)
2370-
symloc = group().find_symloc(s.name(), SymArena::Outputs);
2361+
auto symloc = group().find_symloc(s.name(), inst()->layername(),
2362+
SymArena::Outputs);
23712363
if (!symloc) {
23722364
// std::cout << "No output copy for " << s.name()
23732365
// << " because no symloc was found\n";

src/liboslexec/llvm_instance.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -818,11 +818,8 @@ BackendLLVM::llvm_assign_initial_value(const Symbol& sym, bool force)
818818
llvm::Value* got_userdata = nullptr;
819819

820820
// See if userdata input placement has been used for this symbol
821-
ustring layersym = ustring::fmtformat("{}.{}", inst()->layername(),
822-
sym.name());
823-
symloc = group().find_symloc(layersym, SymArena::UserData);
824-
if (!symloc)
825-
symloc = group().find_symloc(sym.name(), SymArena::UserData);
821+
symloc = group().find_symloc(sym.name(), inst()->layername(),
822+
SymArena::UserData);
826823
if (symloc) {
827824
// We had a userdata pre-placement record for this variable.
828825
// Just copy from the correct offset location!
@@ -1793,13 +1790,8 @@ BackendLLVM::build_llvm_instance(bool groupentry)
17931790
{
17941791
if (!s.renderer_output()) // Skip if not a renderer output
17951792
continue;
1796-
// Try to look up the sym among the outputs with the full layer.name
1797-
// specification first. If that fails, look for name only.
1798-
ustring layersym = ustring::fmtformat("{}.{}", inst()->layername(),
1799-
s.name());
1800-
auto symloc = group().find_symloc(layersym, SymArena::Outputs);
1801-
if (!symloc)
1802-
symloc = group().find_symloc(s.name(), SymArena::Outputs);
1793+
auto symloc = group().find_symloc(s.name(), inst()->layername(),
1794+
SymArena::Outputs);
18031795
if (!symloc) {
18041796
// std::cout << "No output copy for " << s.name()
18051797
// << " because no symloc was found\n";

src/liboslexec/oslexec_pvt.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1931,6 +1931,21 @@ class ShaderGroup {
19311931
return nullptr;
19321932
}
19331933

1934+
// Find the SymLocationDesc for this named param but only if it matches
1935+
// the arena type, returning its pointer or nullptr if that name is not
1936+
// found.
1937+
// Try to look up the sym with the full layer.name specification first.
1938+
// If that fails, try again based on name only.
1939+
const SymLocationDesc* find_symloc(ustring name, ustring layer,
1940+
SymArena arena) const
1941+
{
1942+
ustring layersym = ustring::fmtformat("{}.{}", layer, name);
1943+
auto symloc = find_symloc(layersym, arena);
1944+
if (!symloc)
1945+
symloc = find_symloc(name, arena);
1946+
return symloc;
1947+
}
1948+
19341949
// Given a data block for interactive params, allocate space for it to
19351950
// live with the group and copy the initial data.
19361951
void setup_interactive_arena(cspan<uint8_t> paramblock);

src/liboslexec/runtimeoptimize.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2698,6 +2698,15 @@ RuntimeOptimizer::track_variable_dependencies()
26982698
if (s.symtype() == SymTypeGlobal && s.everwritten()
26992699
&& !s.typespec().is_closure_based() && s.mangled() != Strings::N)
27002700
s.has_derivs(true);
2701+
// If the renderer requests a symbol to be written as an output with
2702+
// derivs, mark them to be generated.
2703+
if (s.renderer_output()) {
2704+
auto symloc = group().find_symloc(s.name(), inst()->layername(),
2705+
SymArena::Outputs);
2706+
if (symloc && symloc->derivs && s.everwritten()
2707+
&& !s.typespec().is_closure_based())
2708+
s.has_derivs(true);
2709+
}
27012710
if (s.has_derivs())
27022711
add_dependency(symdeps, DerivSym, snum);
27032712
++snum;

0 commit comments

Comments
 (0)