diff options
Diffstat (limited to 'runtime/test/queue_proxy_test.cpp')
| -rw-r--r-- | runtime/test/queue_proxy_test.cpp | 65 |
1 files changed, 58 insertions, 7 deletions
diff --git a/runtime/test/queue_proxy_test.cpp b/runtime/test/queue_proxy_test.cpp index 69c1c26bd..3d5ed98fa 100644 --- a/runtime/test/queue_proxy_test.cpp +++ b/runtime/test/queue_proxy_test.cpp | |||
| @@ -1067,26 +1067,77 @@ unsigned differential_jobs() { | |||
| 1067 | return half < 1 ? 1 : half > 8 ? 8 : half; | 1067 | return half < 1 ? 1 : half > 8 ? 8 : half; |
| 1068 | } | 1068 | } |
| 1069 | 1069 | ||
| 1070 | // Cases that fault in the PC runtime (17..20, 25), modify device residency (1, 2, 26..29), or touch the shared | ||
| 1071 | // handle subsystem (30, 31) are isolated in child processes so the host device remains completely clean and intact. | ||
| 1072 | // Non-destructive argument-validation and proxy-wrapping cases run in-process for speed (<1 ms each). | ||
| 1073 | bool is_isolated_diff_case(int index) { | ||
| 1074 | if (index == 1 || index == 2) return true; // residency (descriptor heap) | ||
| 1075 | if (index >= 17 && index <= 20) return true; // faults on PC runtime (queue null args) | ||
| 1076 | if (index == 25) return true; // faults on PC runtime (null fence entry) | ||
| 1077 | if (index >= 26 && index <= 29) return true; // residency (MakeResident/Evict/Priority/Enqueue) | ||
| 1078 | if (index == 30 || index == 31) return true; // shared handle creation | ||
| 1079 | return false; | ||
| 1080 | } | ||
| 1081 | |||
| 1082 | ChildResult run_in_process(const char* label, ID3D12Device* target_device, int index, bool through_proxy, | ||
| 1083 | unsigned long validation_errors = 0) { | ||
| 1084 | ChildResult r{}; | ||
| 1085 | Event event; | ||
| 1086 | DiffContext context{}; | ||
| 1087 | Ref<ID3D12CommandQueue> queue; | ||
| 1088 | Ref<ID3D12Fence> fence, second; | ||
| 1089 | if (make_context(label, target_device, context, queue, fence, second)) return r; | ||
| 1090 | if (xs::is_queue_proxy(context.queue) != through_proxy || xs::is_fence_proxy(context.fence) != through_proxy) { | ||
| 1091 | return r; | ||
| 1092 | } | ||
| 1093 | context.event = event.h; | ||
| 1094 | HRESULT result = S_OK; | ||
| 1095 | const bool ran = run_guarded(kDiffCases[index].run, &context, &result); | ||
| 1096 | const HRESULT removed = ran ? target_device->GetDeviceRemovedReason() : S_OK; | ||
| 1097 | r.ok = true; | ||
| 1098 | r.ran = ran ? 1 : 0; | ||
| 1099 | r.hr = static_cast<unsigned long>(result); | ||
| 1100 | r.removed = static_cast<unsigned long>(removed); | ||
| 1101 | r.validation = validation_errors; | ||
| 1102 | return r; | ||
| 1103 | } | ||
| 1104 | |||
| 1070 | // Each case, in a child process for the real object and in another for the proxy: the same HRESULT, the device | 1105 | // Each case, in a child process for the real object and in another for the proxy: the same HRESULT, the device |
| 1071 | // removed (or not) alike, and no validation errors. A case the real runtime faults on is reported, not compared. | 1106 | // removed (or not) alike, and no validation errors. A case the real runtime faults on is reported, not compared. |
| 1072 | // The children run differential_jobs() at a time; the results are judged afterwards in case order, so the report is | 1107 | // Non-destructive argument-validation and proxy cases run in-process (<1 ms each instead of ~5 s per device creation). |
| 1073 | // the same as one child after another would give (a proxy child whose real one faulted is run but not judged). | 1108 | // Faulting, residency, or shared cases run in isolated child processes using differential_jobs() workers. |
| 1074 | int check_differential(const Backend& b) { | 1109 | int check_differential(const Backend& b) { |
| 1075 | const char* label = b.label; | 1110 | const char* label = b.label; |
| 1076 | int compared = 0, faulting = 0; | 1111 | int compared = 0, faulting = 0; |
| 1077 | constexpr int kCases = static_cast<int>(std::size(kDiffCases)); | 1112 | constexpr int kCases = static_cast<int>(std::size(kDiffCases)); |
| 1078 | std::vector<ChildResult> results(2 * kCases); // [2 * case] real, [2 * case + 1] proxy | 1113 | std::vector<ChildResult> results(2 * kCases); // [2 * case] real, [2 * case + 1] proxy |
| 1079 | { | 1114 | |
| 1080 | std::atomic<int> next{0}; | 1115 | const bool force_isolate_all = GetEnvironmentVariableA("LEONIDA_QUEUE_PROXY_ISOLATE_ALL", nullptr, 0) > 0; |
| 1116 | |||
| 1117 | std::vector<int> child_jobs; | ||
| 1118 | for (int i = 0; i < kCases; ++i) { | ||
| 1119 | if (force_isolate_all || is_isolated_diff_case(i)) { | ||
| 1120 | child_jobs.push_back(2 * i); // real | ||
| 1121 | child_jobs.push_back(2 * i + 1); // proxy | ||
| 1122 | } else { | ||
| 1123 | results[2 * i] = run_in_process(label, b.real, i, false); | ||
| 1124 | results[2 * i + 1] = run_in_process(label, b.device, i, true); | ||
| 1125 | } | ||
| 1126 | } | ||
| 1127 | |||
| 1128 | if (!child_jobs.empty()) { | ||
| 1129 | std::atomic<size_t> next{0}; | ||
| 1081 | const auto work = [&] { | 1130 | const auto work = [&] { |
| 1082 | for (int job; (job = next.fetch_add(1)) < 2 * kCases;) | 1131 | for (size_t idx; (idx = next.fetch_add(1)) < child_jobs.size();) { |
| 1132 | const int job = child_jobs[idx]; | ||
| 1083 | results[job] = run_child(b.kind, job / 2, job % 2 == 1); | 1133 | results[job] = run_child(b.kind, job / 2, job % 2 == 1); |
| 1134 | } | ||
| 1084 | }; | 1135 | }; |
| 1085 | const unsigned jobs = differential_jobs(); | 1136 | const unsigned jobs = differential_jobs(); |
| 1086 | std::vector<std::thread> pool; | 1137 | std::vector<std::thread> pool; |
| 1087 | try { | 1138 | try { |
| 1088 | for (unsigned t = 1; t < jobs; ++t) pool.emplace_back(work); | 1139 | for (unsigned t = 1; t < jobs && t < child_jobs.size(); ++t) pool.emplace_back(work); |
| 1089 | } catch (const std::system_error& e) { // fewer helpers; this thread still runs every job left | 1140 | } catch (const std::system_error& e) { |
| 1090 | std::fprintf(stderr, "%s: %zu of %u differential runner threads (%s)\n", label, pool.size() + 1, jobs, | 1141 | std::fprintf(stderr, "%s: %zu of %u differential runner threads (%s)\n", label, pool.size() + 1, jobs, |
| 1091 | e.what()); | 1142 | e.what()); |
| 1092 | } | 1143 | } |