diff --git a/clean/runtime/device.cpp b/clean/runtime/device.cpp index 6c59a79d..b6df236e 100644 --- a/clean/runtime/device.cpp +++ b/clean/runtime/device.cpp @@ -821,8 +821,15 @@ void trace_launch(const std::string& kernel, unsigned grid, unsigned block, cons return p && *p ? std::fopen(p, "a") : (FILE*)nullptr; }(); static std::mutex mutex; + static const unsigned long long cap = [] { // WG_LAUNCH_TRACE_MAX=: stop after that many (0 / unset: no cap) + const char* m = std::getenv("WG_LAUNCH_TRACE_MAX"); + return m && *m ? std::strtoull(m, nullptr, 10) : 0ull; + }(); + static unsigned long long lines = 0; if (!fp) return; std::lock_guard lock(mutex); + if (cap && lines >= cap) return; + ++lines; if (where) std::fprintf(fp, "%s %u %u %s\n", kernel.c_str(), grid, block, where); else diff --git a/clean/runtime/device.h b/clean/runtime/device.h index 5a3b1c52..e3fc0517 100644 --- a/clean/runtime/device.h +++ b/clean/runtime/device.h @@ -176,7 +176,9 @@ std::unique_ptr make_dx12_device(const std::string& rocm_dir, const std: // Uses /dx12/manifest.json and WG_D3D12_ARENA_MB (16..4095, default 2560). std::unique_ptr make_d3d12_device(const std::string& build_dir, std::string* err); -// Diagnostics: WG_LAUNCH_TRACE= appends one line per kernel launch ("kernel grid block [where]"). +// Diagnostics: WG_LAUNCH_TRACE= appends one line per kernel launch ("kernel grid block [where]"); +// WG_LAUNCH_TRACE_MAX= stops it after that many lines. The interop's runtime options launch_trace= and +// launch_trace_max= set both (a game started by its store launcher does not inherit our environment). void trace_launch(const std::string& kernel, unsigned grid, unsigned block, const char* where = nullptr); } // namespace wgrt diff --git a/clean/runtime/interop/backend.cpp b/clean/runtime/interop/backend.cpp index 3151df27..ba16de34 100644 --- a/clean/runtime/interop/backend.cpp +++ b/clean/runtime/interop/backend.cpp @@ -238,6 +238,12 @@ Options parse_options(const char* text) { else if (key == "input_copy") o.input_copy = value == "1"; else if (key == "output_copy") o.output_copy = value == "1"; else if (key == "test_view") o.test_view = value == "depth" ? 1 : value == "motion" ? 2 : 0; +#ifdef _WIN32 + // diagnostics (a game started by its store launcher does not inherit our environment): launch_trace= sets + // WG_LAUNCH_TRACE (device.cpp trace_launch, one line per kernel launch), launch_trace_max= caps it + else if (key == "launch_trace") _putenv_s("WG_LAUNCH_TRACE", value.c_str()); + else if (key == "launch_trace_max") _putenv_s("WG_LAUNCH_TRACE_MAX", value.c_str()); +#endif else { o.unknown += (o.unknown.empty() ? "" : ", ") + key; o.runtime += (o.runtime.empty() ? "" : ";") + key + (eq == std::string::npos ? "" : "=" + value);