diff options
| author | Rain156 <77776581+Rain156@users.noreply.github.com> | 2026-11-24 21:17:25 +0800 |
|---|---|---|
| committer | Rain156 <77776581+Rain156@users.noreply.github.com> | 2026-11-24 21:17:25 +0800 |
| commit | 3c7927ea266c8dcb798de3462e9d4f4af2cdfc82 (patch) | |
| tree | 3afa7977e790954d62182cbc58bf7b9ec262d03e /runtime/src | |
| parent | 65b8569bbce801f5d083fd5c91cd8bc13f825ece (diff) | |
| parent | 4ed6229e731bbcea95ec29b0a8f4f11cade1c439 (diff) | |
Integrate #526 for the Windows first-run UI
Diffstat (limited to 'runtime/src')
| -rw-r--r-- | runtime/src/command_list.h | 3 | ||||
| -rw-r--r-- | runtime/src/frame_pacer.h | 25 | ||||
| -rw-r--r-- | runtime/src/pe_loader.cpp | 7 |
3 files changed, 29 insertions, 6 deletions
diff --git a/runtime/src/command_list.h b/runtime/src/command_list.h index 7c5c09e0a..595110f36 100644 --- a/runtime/src/command_list.h +++ b/runtime/src/command_list.h | |||
| @@ -587,6 +587,9 @@ enum class IndirectKind : std::uint8_t { | |||
| 587 | draw = 0, | 587 | draw = 0, |
| 588 | draw_indexed = 1, | 588 | draw_indexed = 1, |
| 589 | dispatch = 2, | 589 | dispatch = 2, |
| 590 | // D3D12_DISPATCH_MESH_ARGUMENTS. Created on a device with mesh shaders; ExecuteIndirect with it records nothing | ||
| 591 | // yet (the replay is #3777's), so a title that only creates such a signature at startup goes on. | ||
| 592 | dispatch_mesh = 3, | ||
| 590 | }; | 593 | }; |
| 591 | 594 | ||
| 592 | struct ExecuteIndirect { | 595 | struct ExecuteIndirect { |
diff --git a/runtime/src/frame_pacer.h b/runtime/src/frame_pacer.h index fa9c20df1..5de8e9b79 100644 --- a/runtime/src/frame_pacer.h +++ b/runtime/src/frame_pacer.h | |||
| @@ -37,7 +37,9 @@ | |||
| 37 | #include <deque> | 37 | #include <deque> |
| 38 | #include <functional> | 38 | #include <functional> |
| 39 | #include <limits> | 39 | #include <limits> |
| 40 | #include <memory> | ||
| 40 | #include <mutex> | 41 | #include <mutex> |
| 42 | #include <utility> | ||
| 41 | 43 | ||
| 42 | namespace leonida { | 44 | namespace leonida { |
| 43 | 45 | ||
| @@ -143,9 +145,19 @@ struct FrameStatistic { | |||
| 143 | float percent_scanned = 0.0f; // display entries: where the scan was when the frame came up (0 at a vblank) | 145 | float percent_scanned = 0.0f; // display entries: where the scan was when the frame came up (0 at a vblank) |
| 144 | }; | 146 | }; |
| 145 | 147 | ||
| 148 | class FrameTokenSource { | ||
| 149 | public: | ||
| 150 | std::uint64_t issue() { return last_.fetch_add(1, std::memory_order_acq_rel) + 1; } | ||
| 151 | std::uint64_t issued() const { return last_.load(std::memory_order_acquire); } | ||
| 152 | |||
| 153 | private: | ||
| 154 | std::atomic<std::uint64_t> last_{0}; | ||
| 155 | }; | ||
| 156 | |||
| 146 | class FramePacer { | 157 | class FramePacer { |
| 147 | public: | 158 | public: |
| 148 | explicit FramePacer(FrameClock& clock) : clock_(clock) { | 159 | explicit FramePacer(FrameClock& clock, std::shared_ptr<FrameTokenSource> tokens = nullptr) |
| 160 | : clock_(clock), tokens_(tokens ? std::move(tokens) : std::make_shared<FrameTokenSource>()) { | ||
| 149 | clock_.set_wake([this] { | 161 | clock_.set_wake([this] { |
| 150 | { std::lock_guard guard(mutex_); } | 162 | { std::lock_guard guard(mutex_); } |
| 151 | cv_.notify_all(); | 163 | cv_.notify_all(); |
| @@ -263,7 +275,7 @@ public: | |||
| 263 | std::lock_guard guard(mutex_); | 275 | std::lock_guard guard(mutex_); |
| 264 | if (issue) *issue = TokenIssue::none; | 276 | if (issue) *issue = TokenIssue::none; |
| 265 | if (suspended_) return pacer_hr::invalid_state; | 277 | if (suspended_) return pacer_hr::invalid_state; |
| 266 | if (token > issued_) return pacer_hr::invalid_arg; | 278 | if (token > tokens_->issued()) return pacer_hr::invalid_arg; |
| 267 | if (issue) { | 279 | if (issue) { |
| 268 | if (token == 0) *issue = TokenIssue::null_token; | 280 | if (token == 0) *issue = TokenIssue::null_token; |
| 269 | else if (token == last_presented_) *issue = TokenIssue::repeated; | 281 | else if (token == last_presented_) *issue = TokenIssue::repeated; |
| @@ -357,7 +369,8 @@ public: | |||
| 357 | } | 369 | } |
| 358 | 370 | ||
| 359 | bool suspended() const { std::lock_guard guard(mutex_); return suspended_; } | 371 | bool suspended() const { std::lock_guard guard(mutex_); return suspended_; } |
| 360 | std::uint64_t tokens_issued() const { std::lock_guard guard(mutex_); return issued_; } | 372 | std::uint64_t tokens_issued() const { return tokens_->issued(); } |
| 373 | const std::shared_ptr<FrameTokenSource>& token_source() const { return tokens_; } | ||
| 361 | std::uint32_t frames_in_flight() { | 374 | std::uint32_t frames_in_flight() { |
| 362 | std::lock_guard guard(mutex_); | 375 | std::lock_guard guard(mutex_); |
| 363 | retire_locked(clock_.now_us()); | 376 | retire_locked(clock_.now_us()); |
| @@ -408,7 +421,7 @@ private: | |||
| 408 | const std::uint64_t now = clock_.now_us(); | 421 | const std::uint64_t now = clock_.now_us(); |
| 409 | retire_locked(now); | 422 | retire_locked(now); |
| 410 | if (uncapped_) { // no vblank grid and no latency throttle: a token at once, due now | 423 | if (uncapped_) { // no vblank grid and no latency throttle: a token at once, due now |
| 411 | *token = ++issued_; | 424 | *token = tokens_->issue(); |
| 412 | Record record; | 425 | Record record; |
| 413 | record.token = *token; | 426 | record.token = *token; |
| 414 | record.origin_us = now; | 427 | record.origin_us = now; |
| @@ -426,7 +439,7 @@ private: | |||
| 426 | const std::int64_t newest = std::int64_t((now - first) / period_us_); | 439 | const std::int64_t newest = std::int64_t((now - first) / period_us_); |
| 427 | const std::int64_t origin = std::max(next, newest); | 440 | const std::int64_t origin = std::max(next, newest); |
| 428 | last_origin_ = origin; | 441 | last_origin_ = origin; |
| 429 | *token = ++issued_; | 442 | *token = tokens_->issue(); |
| 430 | Record record; | 443 | Record record; |
| 431 | record.token = *token; | 444 | record.token = *token; |
| 432 | record.origin_us = first + std::uint64_t(origin) * period_us_; | 445 | record.origin_us = first + std::uint64_t(origin) * period_us_; |
| @@ -457,7 +470,7 @@ private: | |||
| 457 | std::uint32_t offset_us_ = 0; | 470 | std::uint32_t offset_us_ = 0; |
| 458 | std::uint64_t epoch_us_ = 0; | 471 | std::uint64_t epoch_us_ = 0; |
| 459 | std::int64_t last_origin_ = 0; // origin 0 is the epoch itself, which has passed | 472 | std::int64_t last_origin_ = 0; // origin 0 is the epoch itself, which has passed |
| 460 | std::uint64_t issued_ = 0; | 473 | std::shared_ptr<FrameTokenSource> tokens_; |
| 461 | std::uint64_t last_presented_ = 0; | 474 | std::uint64_t last_presented_ = 0; |
| 462 | std::uint64_t immediate_presents_ = 0; | 475 | std::uint64_t immediate_presents_ = 0; |
| 463 | std::deque<Pending> pending_; | 476 | std::deque<Pending> pending_; |
diff --git a/runtime/src/pe_loader.cpp b/runtime/src/pe_loader.cpp index c29a288a9..cc4ae88aa 100644 --- a/runtime/src/pe_loader.cpp +++ b/runtime/src/pe_loader.cpp | |||
| @@ -1094,6 +1094,7 @@ Loader::~Loader() { | |||
| 1094 | entry(m.base, DLL_PROCESS_DETACH, nullptr); // explicit unload; the return value is ignored | 1094 | entry(m.base, DLL_PROCESS_DETACH, nullptr); // explicit unload; the return value is ignored |
| 1095 | } | 1095 | } |
| 1096 | } | 1096 | } |
| 1097 | shims::remove_xmem_allocation_hooks(this); | ||
| 1097 | shims::remove_bundled_loader(this); | 1098 | shims::remove_bundled_loader(this); |
| 1098 | shims::remove_module_lookup(this); | 1099 | shims::remove_module_lookup(this); |
| 1099 | for (auto* m : order_) { | 1100 | for (auto* m : order_) { |
| @@ -1498,6 +1499,12 @@ Module& Loader::map_image(const std::filesystem::path& path, const std::string& | |||
| 1498 | // installed here, before bind_imports can return control to the caller and before any image code can run. | 1499 | // installed here, before bind_imports can return control to the caller and before any image code can run. |
| 1499 | initialize_tls(*m); | 1500 | initialize_tls(*m); |
| 1500 | parse_exports(*m); | 1501 | parse_exports(*m); |
| 1502 | if (auto it = m->exports.find("__XMemAllocationHooks__"); it != m->exports.end()) { | ||
| 1503 | const auto offset = static_cast<uint64_t>(static_cast<uint8_t*>(it->second) - m->base); | ||
| 1504 | if (offset <= m->size && m->size - offset >= sizeof(shims::XMemAllocationHooks)) { | ||
| 1505 | shims::add_xmem_allocation_hooks(this, static_cast<const shims::XMemAllocationHooks*>(it->second)); | ||
| 1506 | } | ||
| 1507 | } | ||
| 1501 | return *m; | 1508 | return *m; |
| 1502 | } | 1509 | } |
| 1503 | 1510 | ||