diff options
| author | Galaxy <jojomalrbx@gmail.com> | 2026-11-25 13:04:29 -0600 |
|---|---|---|
| committer | Galaxy <jojomalrbx@gmail.com> | 2026-11-25 13:04:29 -0600 |
| commit | e6f34ed080508b54d93e162e3aa5bdca66980bbd (patch) | |
| tree | 0688bd750b505f1d2d2d8989e61aae0576cf7e13 /runtime/src | |
| parent | fe1553456f90fa53226714929e5b176c75dd621d (diff) | |
d3d12: say when the driver's pipeline cache stops keeping new pipelines (RT-PIPELINE-CACHE-GROWTH-STALL)
A driver can stop adding to a large VkPipelineCache with no error. On NVIDIA 610.88 a 1.23 GB or 1.35 GB cache
came back the same size to the byte after a 2 s compile, so the next run compiles the same pipelines again and
nothing says why. The runtime now takes the cache's size at creation and at each session save, counts the title's
pipeline builds that took at least 200 ms, and logs once when 16 or more compiled while the cache grew less than
64 KiB. pipeline_cache_store_test covers the decision; docs/d3d12_vulkan.md records the measurements.
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 6d519d99b..19913c97f 100644 --- a/runtime/src/pipeline_cache_store.h +++ b/runtime/src/pipeline_cache_store.h | |||
| @@ -66,4 +66,42 @@ inline bool header_matches(const void* data, std::size_t size, const cached_pso: | |||
| 66 | std::memcmp(bytes + 16, identity.cache_uuid, sizeof(identity.cache_uuid)) == 0; | 66 | std::memcmp(bytes + 16, identity.cache_uuid, sizeof(identity.cache_uuid)) == 0; |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | // Whether the driver still keeps the pipelines the title compiles (RT-PIPELINE-CACHE-GROWTH-STALL). A driver can stop | ||
| 70 | // 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 | ||
| 71 | // or 1.35 GB cache came back from vkGetPipelineCacheData the same size to the byte, where an empty cache grew ~210 KiB | ||
| 72 | // for the same module; an older cache of other pipelines stopped at 4.9 GB, so there is no fixed size to test. | ||
| 73 | // Instead two sizes of the live cache are compared with the builds that compiled in between (pipeline_profile:: | ||
| 74 | // compiled_builds): each one adds tens to hundreds of KiB when the driver keeps it. | ||
| 75 | inline constexpr unsigned long long stalled_after_builds = 16; | ||
| 76 | inline constexpr std::size_t stalled_below_bytes = std::size_t{64} << 10; // 64 KiB | ||
| 77 | |||
| 78 | class GrowthWatch { | ||
| 79 | public: | ||
| 80 | // The cache's size and the compiled-build count when it is created, or at a save. | ||
| 81 | void observe(std::size_t bytes, unsigned long long compiled) { | ||
| 82 | bytes_ = bytes; | ||
| 83 | compiled_ = compiled; | ||
| 84 | known_ = true; | ||
| 85 | } | ||
| 86 | |||
| 87 | // At a later size: true once, the first time at least stalled_after_builds builds compiled since the last | ||
| 88 | // observation while the cache grew by less than stalled_below_bytes. The new size is recorded either way. | ||
| 89 | bool stalled(std::size_t bytes, unsigned long long compiled) { | ||
| 90 | const bool stall = known_ && !reported_ && compiled >= compiled_ && compiled - compiled_ >= stalled_after_builds && | ||
| 91 | bytes < bytes_ + stalled_below_bytes; | ||
| 92 | if (stall) reported_ = true; | ||
| 93 | observe(bytes, compiled); | ||
| 94 | return stall; | ||
| 95 | } | ||
| 96 | |||
| 97 | std::size_t bytes() const { return bytes_; } | ||
| 98 | unsigned long long compiled() const { return compiled_; } | ||
| 99 | |||
| 100 | private: | ||
| 101 | std::size_t bytes_ = 0; | ||
| 102 | unsigned long long compiled_ = 0; | ||
| 103 | bool known_ = false; | ||
| 104 | bool reported_ = false; | ||
| 105 | }; | ||
| 106 | |||
| 69 | } // namespace leonida::pipeline_cache_store | 107 | } // 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, |