diff options
| author | NotRexed <therealnothingfn@gmail.com> | 2026-11-30 13:18:51 -0500 |
|---|---|---|
| committer | NotRexed <therealnothingfn@gmail.com> | 2026-11-30 13:18:51 -0500 |
| commit | 6cdc0a0d13e33daeae13f7fcfdde0907c46bc73d (patch) | |
| tree | 5803652915939addf7962b933ba4ffa30420fbcb /runtime/src | |
| parent | f7857c4d6f3314d5325daae7651a85a333c3afab (diff) | |
| parent | ad36782c6d54af6af343def1a86861d760de9e96 (diff) | |
Merge remote-tracking branch 'origin/main' into push/main-1130
Diffstat (limited to 'runtime/src')
| -rw-r--r-- | runtime/src/pipeline_cache_store.h | 38 | ||||
| -rw-r--r-- | runtime/src/pipeline_profile.h | 16 |
2 files changed, 51 insertions, 3 deletions
diff --git a/runtime/src/pipeline_cache_store.h b/runtime/src/pipeline_cache_store.h index 5b93d93f0..151ada16e 100644 --- a/runtime/src/pipeline_cache_store.h +++ b/runtime/src/pipeline_cache_store.h | |||
| @@ -73,4 +73,42 @@ inline bool header_matches(const void* data, std::size_t size, const cached_pso: | |||
| 73 | std::memcmp(bytes + 16, identity.cache_uuid, sizeof(identity.cache_uuid)) == 0; | 73 | std::memcmp(bytes + 16, identity.cache_uuid, sizeof(identity.cache_uuid)) == 0; |
| 74 | } | 74 | } |
| 75 | 75 | ||
| 76 | // Whether the driver still keeps the pipelines the title compiles (RT-PIPELINE-CACHE-GROWTH-STALL). A driver can stop | ||
| 77 | // adding to a large cache without any error. Measured on NVIDIA 610.88 (RTX 5060 Ti): after a 2 s compile, a 1.23 GB | ||
| 78 | // or 1.35 GB cache came back from vkGetPipelineCacheData the same size to the byte, where an empty cache grew ~210 KiB | ||
| 79 | // for the same module; an older cache of other pipelines stopped at 4.9 GB, so there is no fixed size to test. | ||
| 80 | // Instead two sizes of the live cache are compared with the builds that compiled in between (pipeline_profile:: | ||
| 81 | // compiled_builds): each one adds tens to hundreds of KiB when the driver keeps it. | ||
| 82 | inline constexpr unsigned long long stalled_after_builds = 16; | ||
| 83 | inline constexpr std::size_t stalled_below_bytes = std::size_t{64} << 10; // 64 KiB | ||
| 84 | |||
| 85 | class GrowthWatch { | ||
| 86 | public: | ||
| 87 | // The cache's size and the compiled-build count when it is created, or at a save. | ||
| 88 | void observe(std::size_t bytes, unsigned long long compiled) { | ||
| 89 | bytes_ = bytes; | ||
| 90 | compiled_ = compiled; | ||
| 91 | known_ = true; | ||
| 92 | } | ||
| 93 | |||
| 94 | // At a later size: true once, the first time at least stalled_after_builds builds compiled since the last | ||
| 95 | // observation while the cache grew by less than stalled_below_bytes. The new size is recorded either way. | ||
| 96 | bool stalled(std::size_t bytes, unsigned long long compiled) { | ||
| 97 | const bool stall = known_ && !reported_ && compiled >= compiled_ && compiled - compiled_ >= stalled_after_builds && | ||
| 98 | bytes < bytes_ + stalled_below_bytes; | ||
| 99 | if (stall) reported_ = true; | ||
| 100 | observe(bytes, compiled); | ||
| 101 | return stall; | ||
| 102 | } | ||
| 103 | |||
| 104 | std::size_t bytes() const { return bytes_; } | ||
| 105 | unsigned long long compiled() const { return compiled_; } | ||
| 106 | |||
| 107 | private: | ||
| 108 | std::size_t bytes_ = 0; | ||
| 109 | unsigned long long compiled_ = 0; | ||
| 110 | bool known_ = false; | ||
| 111 | bool reported_ = false; | ||
| 112 | }; | ||
| 113 | |||
| 76 | } // namespace leonida::pipeline_cache_store | 114 | } // namespace leonida::pipeline_cache_store |
diff --git a/runtime/src/pipeline_profile.h b/runtime/src/pipeline_profile.h index f81c00c7d..965d8f525 100644 --- a/runtime/src/pipeline_profile.h +++ b/runtime/src/pipeline_profile.h | |||
| @@ -39,23 +39,33 @@ inline long long thread_cpu_us() { | |||
| 39 | return -1; | 39 | return -1; |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | // Title pipeline builds that took long enough to have compiled rather than come from the pipeline cache: a cache hit | ||
| 43 | // takes a few milliseconds, also while the title keeps every core busy. Counted whether or not profiling is on; the | ||
| 44 | // session cache save compares the count with how much the cache grew (pipeline_cache_store::GrowthWatch). | ||
| 45 | inline constexpr long long compiled_build_us = 200000; // 200 ms | ||
| 46 | inline std::atomic<unsigned long long>& compiled_builds() { | ||
| 47 | static std::atomic<unsigned long long> count{0}; | ||
| 48 | return count; | ||
| 49 | } | ||
| 50 | |||
| 42 | class DriverCall { | 51 | class DriverCall { |
| 43 | public: | 52 | public: |
| 44 | DriverCall(const char* stage, const char* origin, const char* program, const char* fragment = "-", | 53 | DriverCall(const char* stage, const char* origin, const char* program, const char* fragment = "-", |
| 45 | unsigned unbound = 0) { | 54 | unsigned unbound = 0) |
| 55 | : start_(std::chrono::steady_clock::now()) { | ||
| 46 | if (!enabled()) return; | 56 | if (!enabled()) return; |
| 47 | static std::atomic<unsigned long long> sequence{0}; | 57 | static std::atomic<unsigned long long> sequence{0}; |
| 48 | id_ = sequence.fetch_add(1, std::memory_order_relaxed) + 1; | 58 | id_ = sequence.fetch_add(1, std::memory_order_relaxed) + 1; |
| 49 | start_ = std::chrono::steady_clock::now(); | ||
| 50 | cpu_start_ = thread_cpu_us(); | 59 | cpu_start_ = thread_cpu_us(); |
| 51 | std::fprintf(stderr, "[rt] pso-driver begin id=%llu unix_ms=%lld stage=%s origin=%s program=%s ps=%s mask=%u\n", | 60 | std::fprintf(stderr, "[rt] pso-driver begin id=%llu unix_ms=%lld stage=%s origin=%s program=%s ps=%s mask=%u\n", |
| 52 | id_, unix_ms(), stage, origin, program, fragment, unbound); | 61 | id_, unix_ms(), stage, origin, program, fragment, unbound); |
| 53 | } | 62 | } |
| 54 | 63 | ||
| 55 | void finish(int result) const { | 64 | void finish(int result) const { |
| 56 | if (!id_) return; | ||
| 57 | const auto us = std::chrono::duration_cast<std::chrono::microseconds>( | 65 | const auto us = std::chrono::duration_cast<std::chrono::microseconds>( |
| 58 | std::chrono::steady_clock::now() - start_).count(); | 66 | std::chrono::steady_clock::now() - start_).count(); |
| 67 | if (result == 0 && us >= compiled_build_us) compiled_builds().fetch_add(1, std::memory_order_relaxed); | ||
| 68 | if (!id_) return; | ||
| 59 | const long long cpu = thread_cpu_us(); | 69 | const long long cpu = thread_cpu_us(); |
| 60 | std::fprintf(stderr, "[rt] pso-driver end id=%llu unix_ms=%lld us=%lld cpu_us=%lld result=%d\n", | 70 | std::fprintf(stderr, "[rt] pso-driver end id=%llu unix_ms=%lld us=%lld cpu_us=%lld result=%d\n", |
| 61 | id_, unix_ms(), static_cast<long long>(us), cpu >= 0 && cpu_start_ >= 0 ? cpu - cpu_start_ : -1, | 71 | id_, unix_ms(), static_cast<long long>(us), cpu >= 0 && cpu_start_ >= 0 ? cpu - cpu_start_ : -1, |