upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com>2026-11-21 15:17:51 -0500
committerItsNotRexed <300290919+ItsNotRexed@users.noreply.github.com>2026-11-21 15:17:51 -0500
commitce4e26cc14eeaae3ef8b65cd90453bdae3e2718d (patch)
treed202691dd5644b0b651e93f2bff27f9f7f1288b7 /runtime
parentda4d686c7a15bc6de6d843fe6525e59c2a99113f (diff)
parentba191bd6ce7bd92ec5dad0bcf4bd1eab06cba331 (diff)
Merge pull request #113 from eIBart0
Diffstat (limited to 'runtime')
-rw-r--r--runtime/test/vk_pipeline_check.cpp154
1 files changed, 112 insertions, 42 deletions
diff --git a/runtime/test/vk_pipeline_check.cpp b/runtime/test/vk_pipeline_check.cpp
index 319fafbc9..f3d02cdf8 100644
--- a/runtime/test/vk_pipeline_check.cpp
+++ b/runtime/test/vk_pipeline_check.cpp
@@ -20,6 +20,7 @@
20#include <atomic> 20#include <atomic>
21#include <cctype> 21#include <cctype>
22#include <chrono> 22#include <chrono>
23#include <condition_variable>
23#include <cstdio> 24#include <cstdio>
24#include <cstring> 25#include <cstring>
25#include <fstream> 26#include <fstream>
@@ -62,7 +63,15 @@ namespace {
62struct JsonParser { 63struct JsonParser {
63 const std::string& s; 64 const std::string& s;
64 size_t i = 0; 65 size_t i = 0;
66 bool error = false;
67 std::string error_msg;
65 68
69 void fail(const char* ctx) {
70 if (!error) {
71 error = true;
72 error_msg = std::string(ctx) + " at byte " + std::to_string(i);
73 }
74 }
66 void ws() { 75 void ws() {
67 while (i < s.size() && std::isspace(static_cast<unsigned char>(s[i]))) i++; 76 while (i < s.size() && std::isspace(static_cast<unsigned char>(s[i]))) i++;
68 } 77 }
@@ -73,7 +82,7 @@ struct JsonParser {
73 } 82 }
74 std::string parse_string() { 83 std::string parse_string() {
75 ws(); 84 ws();
76 if (i >= s.size() || s[i] != '"') return {}; 85 if (i >= s.size() || s[i] != '"') { fail("expected string"); return {}; }
77 i++; 86 i++;
78 std::string out; 87 std::string out;
79 while (i < s.size() && s[i] != '"') { 88 while (i < s.size() && s[i] != '"') {
@@ -84,18 +93,22 @@ struct JsonParser {
84 out.push_back(s[i++]); 93 out.push_back(s[i++]);
85 } 94 }
86 } 95 }
87 if (i < s.size() && s[i] == '"') i++; 96 if (i >= s.size() || s[i] != '"') { fail("unterminated string"); return out; }
97 i++;
88 return out; 98 return out;
89 } 99 }
90 uint32_t parse_u32() { 100 uint32_t parse_u32() {
91 ws(); 101 ws();
102 const size_t start = i;
92 bool neg = false; 103 bool neg = false;
93 if (i < s.size() && s[i] == '-') { neg = true; i++; } 104 if (i < s.size() && s[i] == '-') { neg = true; i++; }
94 uint32_t v = 0; 105 uint32_t v = 0;
106 const size_t digits_start = i;
95 while (i < s.size() && s[i] >= '0' && s[i] <= '9') { 107 while (i < s.size() && s[i] >= '0' && s[i] <= '9') {
96 v = v * 10 + uint32_t(s[i] - '0'); 108 v = v * 10 + uint32_t(s[i] - '0');
97 i++; 109 i++;
98 } 110 }
111 if (i == digits_start) { i = start; fail("expected unsigned integer"); return 0u; }
99 while (i < s.size() && (s[i] == '.' || s[i] == 'e' || s[i] == 'E' || s[i] == '+' || s[i] == '-' || 112 while (i < s.size() && (s[i] == '.' || s[i] == 'e' || s[i] == 'E' || s[i] == '+' || s[i] == '-' ||
100 (s[i] >= '0' && s[i] <= '9'))) i++; 113 (s[i] >= '0' && s[i] <= '9'))) i++;
101 return neg ? 0u : v; 114 return neg ? 0u : v;
@@ -104,87 +117,118 @@ struct JsonParser {
104 ws(); 117 ws();
105 if (s.compare(i, 4, "true") == 0) { i += 4; return true; } 118 if (s.compare(i, 4, "true") == 0) { i += 4; return true; }
106 if (s.compare(i, 5, "false") == 0) { i += 5; return false; } 119 if (s.compare(i, 5, "false") == 0) { i += 5; return false; }
120 fail("expected boolean");
107 return false; 121 return false;
108 } 122 }
109 void skip_value() { 123 void skip_value() {
110 ws(); 124 ws();
111 if (i >= s.size()) return; 125 if (i >= s.size()) { fail("unexpected end of JSON"); return; }
112 char c = s[i]; 126 char c = s[i];
113 if (c == '"') { parse_string(); return; } 127 if (c == '"') { parse_string(); return; }
114 if (c == '{') { 128 if (c == '{') {
115 i++; 129 i++;
116 while (i < s.size()) { 130 while (!error && i < s.size()) {
117 if (consume('}')) return; 131 if (consume('}')) return;
132 const size_t before = i;
118 parse_string(); 133 parse_string();
119 consume(':'); 134 if (error) return;
135 if (!consume(':')) { fail("expected ':' in object"); return; }
120 skip_value(); 136 skip_value();
121 consume(','); 137 if (error) return;
138 if (consume('}')) return;
139 if (!consume(',') || i == before) { fail("expected ',' or '}' in object"); return; }
122 } 140 }
141 if (!error) fail("unterminated object");
123 return; 142 return;
124 } 143 }
125 if (c == '[') { 144 if (c == '[') {
126 i++; 145 i++;
127 while (i < s.size()) { 146 while (!error && i < s.size()) {
128 if (consume(']')) return; 147 if (consume(']')) return;
148 const size_t before = i;
129 skip_value(); 149 skip_value();
130 consume(','); 150 if (error) return;
151 if (consume(']')) return;
152 if (!consume(',') || i == before) { fail("expected ',' or ']' in array"); return; }
131 } 153 }
154 if (!error) fail("unterminated array");
132 return; 155 return;
133 } 156 }
157 const size_t before = i;
134 while (i < s.size() && s[i] != ',' && s[i] != '}' && s[i] != ']' && 158 while (i < s.size() && s[i] != ',' && s[i] != '}' && s[i] != ']' &&
135 !std::isspace(static_cast<unsigned char>(s[i]))) i++; 159 !std::isspace(static_cast<unsigned char>(s[i]))) i++;
160 if (i == before) fail("unexpected token in value");
136 } 161 }
137 std::vector<uint32_t> parse_u32_array() { 162 std::vector<uint32_t> parse_u32_array() {
138 std::vector<uint32_t> out; 163 std::vector<uint32_t> out;
139 if (!consume('[')) { skip_value(); return out; } 164 if (!consume('[')) { skip_value(); return out; }
140 while (i < s.size()) { 165 while (!error && i < s.size()) {
141 if (consume(']')) break; 166 if (consume(']')) return out;
167 const size_t before = i;
142 out.push_back(parse_u32()); 168 out.push_back(parse_u32());
143 consume(','); 169 if (error) return out;
170 if (consume(']')) return out;
171 if (!consume(',') || i == before) { fail("expected ',' or ']' in u32 array"); return out; }
144 } 172 }
173 if (!error) fail("unterminated u32 array");
145 return out; 174 return out;
146 } 175 }
147 std::vector<std::string> parse_str_array() { 176 std::vector<std::string> parse_str_array() {
148 std::vector<std::string> out; 177 std::vector<std::string> out;
149 if (!consume('[')) { skip_value(); return out; } 178 if (!consume('[')) { skip_value(); return out; }
150 while (i < s.size()) { 179 while (!error && i < s.size()) {
151 if (consume(']')) break; 180 if (consume(']')) return out;
181 const size_t before = i;
152 out.push_back(parse_string()); 182 out.push_back(parse_string());
153 consume(','); 183 if (error) return out;
184 if (consume(']')) return out;
185 if (!consume(',') || i == before) { fail("expected ',' or ']' in string array"); return out; }
154 } 186 }
187 if (!error) fail("unterminated string array");
155 return out; 188 return out;
156 } 189 }
157 std::vector<VertexInputMeta> parse_vertex_inputs() { 190 std::vector<VertexInputMeta> parse_vertex_inputs() {
158 std::vector<VertexInputMeta> out; 191 std::vector<VertexInputMeta> out;
159 if (!consume('[')) { skip_value(); return out; } 192 if (!consume('[')) { skip_value(); return out; }
160 while (i < s.size()) { 193 while (!error && i < s.size()) {
161 if (consume(']')) break; 194 if (consume(']')) return out;
195 const size_t before = i;
162 VertexInputMeta vi; 196 VertexInputMeta vi;
163 if (consume('{')) { 197 if (consume('{')) {
164 while (i < s.size()) { 198 while (!error && i < s.size()) {
165 if (consume('}')) break; 199 if (consume('}')) break;
200 const size_t obj_before = i;
166 std::string k = parse_string(); 201 std::string k = parse_string();
167 consume(':'); 202 if (error) return out;
203 if (!consume(':')) { fail("expected ':' in vertex_inputs entry"); return out; }
168 if (k == "location") vi.location = parse_u32(); 204 if (k == "location") vi.location = parse_u32();
169 else if (k == "type") vi.type = parse_string(); 205 else if (k == "type") vi.type = parse_string();
170 else skip_value(); 206 else skip_value();
171 consume(','); 207 if (error) return out;
208 if (consume('}')) break;
209 if (!consume(',') || i == obj_before) { fail("expected ',' or '}' in vertex_inputs entry"); return out; }
172 } 210 }
211 if (error) return out;
173 out.push_back(std::move(vi)); 212 out.push_back(std::move(vi));
174 } else { 213 } else {
175 skip_value(); 214 skip_value();
215 if (error) return out;
176 } 216 }
177 consume(','); 217 if (consume(']')) return out;
218 if (!consume(',') || i == before) { fail("expected ',' or ']' in vertex_inputs"); return out; }
178 } 219 }
220 if (!error) fail("unterminated vertex_inputs array");
179 return out; 221 return out;
180 } 222 }
181 ShaderMeta parse_meta() { 223 ShaderMeta parse_meta() {
182 ShaderMeta m; 224 ShaderMeta m;
183 if (!consume('{')) { skip_value(); return m; } 225 if (!consume('{')) { skip_value(); return m; }
184 while (i < s.size()) { 226 while (!error && i < s.size()) {
185 if (consume('}')) break; 227 if (consume('}')) return m;
228 const size_t before = i;
186 std::string k = parse_string(); 229 std::string k = parse_string();
187 consume(':'); 230 if (error) return m;
231 if (!consume(':')) { fail("expected ':' in shader metadata"); return m; }
188 if (k == "stage") m.stage = parse_string(); 232 if (k == "stage") m.stage = parse_string();
189 else if (k == "subgroup_size") m.subgroup_size = parse_u32(); 233 else if (k == "subgroup_size") m.subgroup_size = parse_u32();
190 else if (k == "writes_depth") m.writes_depth = parse_bool(); 234 else if (k == "writes_depth") m.writes_depth = parse_bool();
@@ -199,26 +243,37 @@ struct JsonParser {
199 else if (k == "gs_output_locations") { m.gs_output_locations = parse_u32_array(); m.has_gs_output_locations = true; } 243 else if (k == "gs_output_locations") { m.gs_output_locations = parse_u32_array(); m.has_gs_output_locations = true; }
200 else if (k == "vertex_inputs") m.vertex_inputs = parse_vertex_inputs(); 244 else if (k == "vertex_inputs") m.vertex_inputs = parse_vertex_inputs();
201 else skip_value(); 245 else skip_value();
202 consume(','); 246 if (error) return m;
247 if (consume('}')) return m;
248 if (!consume(',') || i == before) { fail("expected ',' or '}' in shader metadata"); return m; }
203 } 249 }
250 if (!error) fail("unterminated shader metadata object");
204 return m; 251 return m;
205 } 252 }
206}; 253};
207 254
208std::map<std::string, ShaderMeta> read_index(const std::string& path) { 255std::map<std::string, ShaderMeta> read_index(const std::string& path, std::string& err) {
209 std::ifstream f(path, std::ios::binary); 256 std::ifstream f(path, std::ios::binary);
210 std::string s((std::istreambuf_iterator<char>(f)), {}); 257 std::string s((std::istreambuf_iterator<char>(f)), {});
211 std::map<std::string, ShaderMeta> out; 258 std::map<std::string, ShaderMeta> out;
212 JsonParser p{s, 0}; 259 JsonParser p{s, 0};
213 if (!p.consume('{')) return out; 260 p.ws();
214 while (p.i < s.size()) { 261 if (p.i >= s.size()) return out;
215 if (p.consume('}')) break; 262 if (!p.consume('{')) { err = "expected '{' at byte " + std::to_string(p.i); return out; }
263 while (!p.error && p.i < s.size()) {
264 if (p.consume('}')) return out;
265 const size_t before = p.i;
216 std::string name = p.parse_string(); 266 std::string name = p.parse_string();
217 if (!p.consume(':')) break; 267 if (p.error) break;
268 if (!p.consume(':')) { p.fail("expected ':' after shader name"); break; }
218 out[name] = p.parse_meta(); 269 out[name] = p.parse_meta();
219 p.consume(','); 270 if (p.error) break;
271 if (p.consume('}')) return out;
272 if (!p.consume(',') || p.i == before) { p.fail("expected ',' or '}' in index.json"); break; }
220 } 273 }
221 return out; 274 if (p.error) { err = p.error_msg; return {}; }
275 err = "unterminated top-level object at byte " + std::to_string(p.i);
276 return {};
222} 277}
223 278
224std::string stub_filename(const char* kind, const std::vector<uint32_t>& raw_locs) { 279std::string stub_filename(const char* kind, const std::vector<uint32_t>& raw_locs) {
@@ -295,7 +350,12 @@ int main(int argc, char** argv) {
295 return 2; 350 return 2;
296 } 351 }
297 352
298 auto index = read_index(dir + "/index.json"); 353 std::string index_err;
354 auto index = read_index(dir + "/index.json", index_err);
355 if (!index_err.empty()) {
356 std::fprintf(stderr, "error: malformed JSON in %s/index.json: %s\n", dir.c_str(), index_err.c_str());
357 return 2;
358 }
299 std::fprintf(stderr, "%zu shaders in index\n", index.size()); 359 std::fprintf(stderr, "%zu shaders in index\n", index.size());
300 360
301 // Build work list: index order (sorted by name), optionally filtered by stage, then [start, start + count). 361 // Build work list: index order (sorted by name), optionally filtered by stage, then [start, start + count).
@@ -383,7 +443,7 @@ int main(int argc, char** argv) {
383#ifdef VK_KHR_MAINTENANCE_8_EXTENSION_NAME 443#ifdef VK_KHR_MAINTENANCE_8_EXTENSION_NAME
384 const bool ext_m8 = link(&m8, reinterpret_cast<VkBaseOutStructure*>(&m8), VK_KHR_MAINTENANCE_8_EXTENSION_NAME, want_m8); 444 const bool ext_m8 = link(&m8, reinterpret_cast<VkBaseOutStructure*>(&m8), VK_KHR_MAINTENANCE_8_EXTENSION_NAME, want_m8);
385#else 445#else
386 const bool ext_m8 = false; 446 (void)want_m8;
387#endif 447#endif
388 VkPhysicalDeviceFeatures2 f2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2}; 448 VkPhysicalDeviceFeatures2 f2{VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2};
389 f2.pNext = chain; 449 f2.pNext = chain;
@@ -772,22 +832,32 @@ int main(int argc, char** argv) {
772 std::vector<std::thread> pool; 832 std::vector<std::thread> pool;
773 for (uint32_t t = 0; t < jobs; t++) pool.emplace_back(worker); 833 for (uint32_t t = 0; t < jobs; t++) pool.emplace_back(worker);
774 // Watchdog: names every compile running past 60 s (about once a minute) and saves the cache every 10 minutes. 834 // Watchdog: names every compile running past 60 s (about once a minute) and saves the cache every 10 minutes.
835 std::condition_variable watch_cv;
836 bool all_done = false;
775 std::thread watch([&] { 837 std::thread watch([&] {
776 auto last_save = std::chrono::steady_clock::now(); 838 auto last_save = std::chrono::steady_clock::now();
777 while (done < work.size()) { 839 std::unique_lock<std::mutex> g(mu);
778 std::this_thread::sleep_for(std::chrono::seconds(5)); 840 while (!all_done) {
841 if (watch_cv.wait_for(g, std::chrono::seconds(5), [&] { return all_done; })) break;
779 const auto now = std::chrono::steady_clock::now(); 842 const auto now = std::chrono::steady_clock::now();
780 { 843 for (auto& [tid, job] : inflight) {
781 std::lock_guard<std::mutex> g(mu); 844 const double s = std::chrono::duration<double>(now - job.second).count();
782 for (auto& [tid, job] : inflight) { 845 if (s > 60 && int(s) % 60 < 5) std::fprintf(stderr, " still compiling %s after %.0fs\n", job.first.c_str(), s);
783 const double s = std::chrono::duration<double>(now - job.second).count(); 846 }
784 if (s > 60 && int(s) % 60 < 5) std::fprintf(stderr, " still compiling %s after %.0fs\n", job.first.c_str(), s); 847 if (now - last_save > std::chrono::minutes(10)) {
785 } 848 g.unlock();
849 save_cache(false);
850 g.lock();
851 last_save = now;
786 } 852 }
787 if (now - last_save > std::chrono::minutes(10)) { save_cache(false); last_save = now; }
788 } 853 }
789 }); 854 });
790 for (auto& t : pool) t.join(); 855 for (auto& t : pool) t.join();
856 {
857 std::lock_guard<std::mutex> g(mu);
858 all_done = true;
859 }
860 watch_cv.notify_one();
791 watch.join(); 861 watch.join();
792 862
793 for (auto& [_, mod] : stub_cache) if (mod) vkDestroyShaderModule(dev, mod, nullptr); 863 for (auto& [_, mod] : stub_cache) if (mod) vkDestroyShaderModule(dev, mod, nullptr);