shader: inline the global memory helpers by default (Ocarina's tree wall)

Ocarina of Time (Switch 2) drew a dense wall of large trees across Hyrule
Field that hardware does not draw. The tree task program computes each
cell's record count as min(end - first, 256) from two consecutive global
loads. With the helpers emitted as DontInline functions, the first of the
two calls returned 0 on NVIDIA (RTX 5080), the subtraction wrapped and
every listed cell drew its 256-record cap.

Measured at one spot with the game's own primitive counter (mesh storage
slot 1, +0x2c): 74,795 cards per pass against 1,811 from the cells' own
records; a second view gave 3,904 = the own-records count with the
helpers inlinable (EDEN_NX2_LEAN_SSBO=0 on the previous build). Writing
the guest words while paused showed the end word was not used and that
the counter followed the "end reads 0" count exactly. The translated
SPIR-V computes both addresses the same way; why the call form fails was
not established.

EDEN_NX2_LEAN_SSBO now defaults to off on both paths; =1 restores the
helpers as calls (faster driver compiles of programs with many candidate
buffers). The VTX-HLE translation key already carries the switch.

VTX-HLE by Vortex727 (https://github.com/Vortex727/FUKKO)
Assisted-by: Claude (debugging, implementation)
Co-Authored-By: Claude <[email protected]>
This commit is contained in:
Duck912 committed 2026-11-09 18:51:24 -05:00
1 parent 6560057a5e
commit df590b2009
3 files changed
+8 -6

No files matched your search

@@ -647,13 +647,15 @@ Id DescType(EmitContext& ctx, Id sampled_type, Id pointer_type, u32 count) {
return pointer_type;
}
}
// EDEN_NX2_LEAN_SSBO=0 turns it off: the global memory helpers are kept as calls and route
// with one switch. Inlined at each of their calls, a program with ~30 candidate buffers took
// NVIDIA's compiler 2.4 s (Ocarina's foliage compute programs; 0.6 s this way, same accesses).
// EDEN_NX2_LEAN_SSBO=1 turns it on: the global memory helpers are kept as calls (DontInline) and
// route with one switch. Inlined at each of their calls, a program with ~30 candidate buffers
// took NVIDIA's compiler 2.4 s (Ocarina's foliage compute programs; 0.6 s as calls). Off by
// default: as calls, the first of two consecutive loads in Ocarina's tree task program returned
// 0 on NVIDIA, so every tree cell drew its 256-record cap (a wall of trees in Hyrule Field).
bool LeanGlobalMemory() {
static const bool enabled = [] {
const char* value = std::getenv("EDEN_NX2_LEAN_SSBO");
return value == nullptr || value[0] != '0';
return value != nullptr && value[0] != '0';
}();
return enabled;
}
+1 -1
View File
@@ -1705,7 +1705,7 @@ TEST_CASE("Translation switches: the hash covers what the recompiler reads and n
REQUIRE(changes([](TranslationSwitches& s) { s.tensor_lowering = 2; }));
REQUIRE(changes([](TranslationSwitches& s) { s.raw_coverage = true; }));
REQUIRE(changes([](TranslationSwitches& s) { s.raw_global_fast = true; }));
REQUIRE(changes([](TranslationSwitches& s) { s.lean_global_memory = false; }));
REQUIRE(changes([](TranslationSwitches& s) { s.lean_global_memory = !s.lean_global_memory; }));
REQUIRE(changes([](TranslationSwitches& s) { s.ro_mirror_exact = true; }));
REQUIRE_FALSE(changes([](TranslationSwitches&) {}));
}
@@ -62,7 +62,7 @@ struct TranslationSwitches {
std::string tensor_mode; ///< its value (selects the HMMA lowering)
u8 tensor_lowering{}; ///< the title's VideoCommon::NativeTensorLowering
bool raw_coverage{}; ///< EDEN_NX2_RAW_COVERAGE=1 (the miss ring reports)
bool lean_global_memory{true}; ///< EDEN_NX2_LEAN_SSBO unset or not 0
bool lean_global_memory{false}; ///< EDEN_NX2_LEAN_SSBO set and not 0
bool raw_global_fast{}; ///< EDEN_NX2_TRY_RAWGLOBAL_FAST=1 (last-hit translation)
bool direct_unused_atomics{}; ///< EDEN_NX2_TRY_DIRECT_UNUSED_ATOMICS=1
bool native_f32_atomics{}; ///< EDEN_NX2_TRY_NATIVE_F32_ATOMICS=1