22 lines
3.9 KiB
Python
22 lines
3.9 KiB
Python
from pathlib import Path
|
|
import sys
|
|
def replace_once(path: Path, old: str, new: str) -> None:
|
|
if not new:
|
|
return
|
|
text = path.read_text(encoding="utf-8")
|
|
count = text.count(new)
|
|
if count != 1:
|
|
raise RuntimeError(f"{path}: expected one current-state match, found {count}")
|
|
path.write_text(text.replace(new, old, 1), encoding="utf-8")
|
|
def main() -> None:
|
|
root = Path(sys.argv[1] if len(sys.argv) > 1 else ".").resolve()
|
|
source = root / "render_3D/render_3D/detail/Gpu_Completion_Service.cpp"
|
|
replace_once(source, '#include "Exception.hpp"\n', '#include "Exception.hpp"\n#include "observation/GPU_Completion.hpp"\n')
|
|
replace_once(source, ' while (count < Private::capacity && !d->in_flight.compare_exchange_weak(count, count + 1, std::memory_order_acq_rel, std::memory_order_relaxed)) {}\n if (count >= Private::capacity) return {{}, Admission_Result::capacity_exhausted};\n', ' while (count < Private::capacity && !d->in_flight.compare_exchange_weak(count, count + 1, std::memory_order_acq_rel, std::memory_order_relaxed)) {}\n if (count >= Private::capacity) {\n observation::trace_gpu_completion_capacity_exhausted(count, Private::capacity);\n return {{}, Admission_Result::capacity_exhausted};\n }\n')
|
|
replace_once(source, ' if (!d->incoming.enqueue(pending)) {\n d->in_flight.fetch_sub(1, std::memory_order_release);\n throw std::bad_alloc{};\n }\n d->request_poll(std::chrono::nanoseconds{1});\n', ' if (!d->incoming.enqueue(pending)) {\n d->in_flight.fetch_sub(1, std::memory_order_release);\n throw std::bad_alloc{};\n }\n observation::trace_gpu_completion_admitted(count + 1, Private::capacity);\n d->request_poll(std::chrono::nanoseconds{1});\n')
|
|
replace_once(source, 'void Gpu_Completion_Service::Private::poll() noexcept {\n std::shared_ptr<Gpu_Completion_Pending_Fence> incoming_value;\n while (incoming.try_dequeue(incoming_value)) {\n active.push_back(std::move(incoming_value));\n incoming_value.reset();\n }\n', 'void Gpu_Completion_Service::Private::poll() noexcept {\n const auto active_before = active.size();\n std::shared_ptr<Gpu_Completion_Pending_Fence> incoming_value;\n while (incoming.try_dequeue(incoming_value)) {\n active.push_back(std::move(incoming_value));\n incoming_value.reset();\n }\n if (active.size() != active_before) observation::trace_gpu_completion_active(in_flight.load(std::memory_order_relaxed), active.size());\n')
|
|
replace_once(source, ' if (status == Gpu_Completion_Pending_Fence::Status::canceled) {\n iterator = active.erase(iterator);\n in_flight.fetch_sub(1, std::memory_order_release);\n continue;\n }\n', ' if (status == Gpu_Completion_Pending_Fence::Status::canceled) {\n iterator = active.erase(iterator);\n const auto remaining = in_flight.fetch_sub(1, std::memory_order_release) - 1;\n observation::trace_gpu_completion_canceled(remaining, active.size(), capacity);\n continue;\n }\n')
|
|
replace_once(source, ' Result result{error, static_cast<std::int32_t>(vulkan_result), pending->observe ? elapsed_nanoseconds(pending->watched_at) : 0};\n iterator = active.erase(iterator);\n in_flight.fetch_sub(1, std::memory_order_release);\n try {\n', ' const auto watched_at = pending->watched_at;\n Result result{error, static_cast<std::int32_t>(vulkan_result), pending->observe ? elapsed_nanoseconds(watched_at) : 0};\n iterator = active.erase(iterator);\n const auto remaining = in_flight.fetch_sub(1, std::memory_order_release) - 1;\n observation::trace_gpu_completion_completed(remaining, active.size(), capacity, watched_at, static_cast<std::int32_t>(error), static_cast<std::int32_t>(vulkan_result));\n try {\n')
|
|
if __name__ == "__main__":
|
|
main()
|