forked from GNOME/gtk
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate-webgpu-performance.ts
More file actions
427 lines (369 loc) · 14.5 KB
/
Copy pathvalidate-webgpu-performance.ts
File metadata and controls
427 lines (369 loc) · 14.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
#!/usr/bin/env -S deno run --allow-read --allow-write --allow-net
// WebGPU GTK4 Performance Validation Suite
// Comprehensive benchmarks following WASM-native architecture principles
import { DemoRunner, type DemoConfig } from './demos/webgpu-widget-factory/demo-deno.ts';
interface BenchmarkResult {
testName: string;
canvasSize: { width: number; height: number };
widgetCount: number;
duration: number;
metrics: {
averageFPS: number;
minFPS: number;
maxFPS: number;
averageFrameTime: number;
totalDrawCalls: number;
totalTriangles: number;
peakMemoryMB: number;
simdSpeedup: number;
};
passed: boolean;
requirements: PerformanceRequirements;
}
interface PerformanceRequirements {
minFPS: number;
maxFrameTime: number;
maxMemoryMB: number;
minSIMDSpeedup: number;
description: string;
}
const PERFORMANCE_REQUIREMENTS: Record<string, PerformanceRequirements> = {
'basic-rendering': {
minFPS: 60,
maxFrameTime: 16.67,
maxMemoryMB: 50,
minSIMDSpeedup: 1.0,
description: 'Basic widget rendering with 50 widgets'
},
'medium-load': {
minFPS: 45,
maxFrameTime: 22.22,
maxMemoryMB: 100,
minSIMDSpeedup: 2.5,
description: 'Medium load with 200 widgets and SIMD optimizations'
},
'high-load': {
minFPS: 30,
maxFrameTime: 33.33,
maxMemoryMB: 200,
minSIMDSpeedup: 3.0,
description: 'High load stress test with 1000 widgets'
},
'extreme-load': {
minFPS: 20,
maxFrameTime: 50.0,
maxMemoryMB: 400,
minSIMDSpeedup: 3.5,
description: 'Extreme load with 2000+ widgets'
},
'high-resolution': {
minFPS: 40,
maxFrameTime: 25.0,
maxMemoryMB: 300,
minSIMDSpeedup: 3.0,
description: 'High resolution 4K rendering'
}
};
class PerformanceValidator {
private results: BenchmarkResult[] = [];
async runAllBenchmarks(): Promise<BenchmarkResult[]> {
console.log('🚀 Starting WebGPU GTK4 Performance Validation Suite');
console.log('=' .repeat(60));
// Test configurations following web-native performance targets
const testConfigs = [
{
name: 'basic-rendering',
config: { canvasWidth: 1024, canvasHeight: 768, stressTestWidgets: 50 },
duration: 15000
},
{
name: 'medium-load',
config: { canvasWidth: 1024, canvasHeight: 768, stressTestWidgets: 200 },
duration: 15000
},
{
name: 'high-load',
config: { canvasWidth: 1024, canvasHeight: 768, stressTestWidgets: 1000 },
duration: 20000
},
{
name: 'extreme-load',
config: { canvasWidth: 1024, canvasHeight: 768, stressTestWidgets: 2000 },
duration: 20000
},
{
name: 'high-resolution',
config: { canvasWidth: 3840, canvasHeight: 2160, stressTestWidgets: 500 },
duration: 20000
}
];
for (const testConfig of testConfigs) {
console.log(`\n📊 Running ${testConfig.name}...`);
console.log(` ${PERFORMANCE_REQUIREMENTS[testConfig.name].description}`);
try {
const result = await this.runBenchmark(
testConfig.name,
testConfig.config,
testConfig.duration
);
this.results.push(result);
this.printResult(result);
} catch (error) {
console.error(`❌ Test ${testConfig.name} failed:`, error);
}
// Cool down between tests
await new Promise(resolve => setTimeout(resolve, 2000));
}
this.printSummary();
return this.results;
}
private async runBenchmark(
testName: string,
config: Partial<DemoConfig>,
duration: number
): Promise<BenchmarkResult> {
const runner = new DemoRunner({
...config,
enableStressTest: true,
enablePerformanceMonitoring: false
});
const requirements = PERFORMANCE_REQUIREMENTS[testName];
const metrics = {
fpsHistory: [] as number[],
frameTimeHistory: [] as number[],
drawCallsHistory: [] as number[],
trianglesHistory: [] as number[],
memoryHistory: [] as number[],
simdSpeedup: 1.0
};
try {
// Initialize demo
await runner.start();
console.log(` Initialized. Running for ${duration / 1000}s...`);
// Collect metrics during test
const startTime = performance.now();
const metricsInterval = setInterval(async () => {
try {
const currentMetrics = await runner.demo.getPerformanceMetrics();
metrics.fpsHistory.push(currentMetrics.fps);
metrics.frameTimeHistory.push(currentMetrics.frameTime);
metrics.drawCallsHistory.push(currentMetrics.drawCalls);
metrics.trianglesHistory.push(currentMetrics.triangles);
metrics.memoryHistory.push(currentMetrics.memoryUsage / (1024 * 1024));
metrics.simdSpeedup = currentMetrics.simdSpeedup;
} catch (error) {
console.warn(' Metrics collection error:', error);
}
}, 500); // Every 500ms
// Wait for test duration
await new Promise(resolve => setTimeout(resolve, duration));
clearInterval(metricsInterval);
await runner.stop();
// Calculate final metrics
const averageFPS = this.average(metrics.fpsHistory);
const minFPS = Math.min(...metrics.fpsHistory);
const maxFPS = Math.max(...metrics.fpsHistory);
const averageFrameTime = this.average(metrics.frameTimeHistory);
const totalDrawCalls = this.sum(metrics.drawCallsHistory);
const totalTriangles = this.sum(metrics.trianglesHistory);
const peakMemoryMB = Math.max(...metrics.memoryHistory);
// Determine if test passed
const passed =
averageFPS >= requirements.minFPS &&
averageFrameTime <= requirements.maxFrameTime &&
peakMemoryMB <= requirements.maxMemoryMB &&
metrics.simdSpeedup >= requirements.minSIMDSpeedup;
return {
testName,
canvasSize: {
width: config.canvasWidth || 1024,
height: config.canvasHeight || 768
},
widgetCount: config.stressTestWidgets || 0,
duration,
metrics: {
averageFPS,
minFPS,
maxFPS,
averageFrameTime,
totalDrawCalls,
totalTriangles,
peakMemoryMB,
simdSpeedup: metrics.simdSpeedup
},
passed,
requirements
};
} catch (error) {
await runner.stop();
throw error;
}
}
private printResult(result: BenchmarkResult): void {
const status = result.passed ? '✅ PASSED' : '❌ FAILED';
console.log(` ${status}`);
console.log(` FPS: ${result.metrics.averageFPS.toFixed(1)} avg (min: ${result.metrics.minFPS.toFixed(1)}, req: ≥${result.requirements.minFPS})`);
console.log(` Frame Time: ${result.metrics.averageFrameTime.toFixed(2)}ms (req: ≤${result.requirements.maxFrameTime}ms)`);
console.log(` Memory: ${result.metrics.peakMemoryMB.toFixed(1)}MB (req: ≤${result.requirements.maxMemoryMB}MB)`);
console.log(` SIMD Speedup: ${result.metrics.simdSpeedup.toFixed(1)}x (req: ≥${result.requirements.minSIMDSpeedup}x)`);
console.log(` Draw Calls: ${result.metrics.totalDrawCalls.toLocaleString()}`);
console.log(` Triangles: ${result.metrics.totalTriangles.toLocaleString()}`);
if (!result.passed) {
console.log(' 🔍 Failure Analysis:');
if (result.metrics.averageFPS < result.requirements.minFPS) {
console.log(` - FPS too low: ${result.metrics.averageFPS.toFixed(1)} < ${result.requirements.minFPS}`);
}
if (result.metrics.averageFrameTime > result.requirements.maxFrameTime) {
console.log(` - Frame time too high: ${result.metrics.averageFrameTime.toFixed(2)}ms > ${result.requirements.maxFrameTime}ms`);
}
if (result.metrics.peakMemoryMB > result.requirements.maxMemoryMB) {
console.log(` - Memory usage too high: ${result.metrics.peakMemoryMB.toFixed(1)}MB > ${result.requirements.maxMemoryMB}MB`);
}
if (result.metrics.simdSpeedup < result.requirements.minSIMDSpeedup) {
console.log(` - SIMD speedup too low: ${result.metrics.simdSpeedup.toFixed(1)}x < ${result.requirements.minSIMDSpeedup}x`);
}
}
}
private printSummary(): void {
console.log('\n📋 Performance Validation Summary');
console.log('=' .repeat(60));
const passed = this.results.filter(r => r.passed).length;
const total = this.results.length;
const passRate = (passed / total) * 100;
console.log(`Tests Passed: ${passed}/${total} (${passRate.toFixed(1)}%)`);
if (passRate === 100) {
console.log('🎉 All performance requirements met!');
console.log(' WebGPU GTK4 renderer achieves web-native performance targets');
} else if (passRate >= 80) {
console.log('⚠️ Most performance requirements met, some optimization needed');
} else {
console.log('❌ Significant performance issues detected');
console.log(' WebGPU renderer requires optimization work');
}
console.log('\n🏆 Performance Highlights:');
const bestFPS = Math.max(...this.results.map(r => r.metrics.averageFPS));
const bestMemory = Math.min(...this.results.map(r => r.metrics.peakMemoryMB));
const bestSIMD = Math.max(...this.results.map(r => r.metrics.simdSpeedup));
console.log(` Peak FPS: ${bestFPS.toFixed(1)}`);
console.log(` Lowest Memory: ${bestMemory.toFixed(1)}MB`);
console.log(` Best SIMD Speedup: ${bestSIMD.toFixed(1)}x`);
// Analyze SIMD effectiveness
const avgSIMDSpeedup = this.average(this.results.map(r => r.metrics.simdSpeedup));
console.log(` Average SIMD Speedup: ${avgSIMDSpeedup.toFixed(1)}x`);
if (avgSIMDSpeedup >= 3.0) {
console.log(' ✅ SIMD optimizations highly effective');
} else if (avgSIMDSpeedup >= 2.0) {
console.log(' ⚠️ SIMD optimizations moderately effective');
} else {
console.log(' ❌ SIMD optimizations need improvement');
}
}
async generateReport(): Promise<void> {
const report = {
timestamp: new Date().toISOString(),
summary: {
totalTests: this.results.length,
passedTests: this.results.filter(r => r.passed).length,
passRate: (this.results.filter(r => r.passed).length / this.results.length) * 100,
avgSIMDSpeedup: this.average(this.results.map(r => r.metrics.simdSpeedup))
},
results: this.results,
recommendations: this.generateRecommendations()
};
const reportPath = './webgpu-performance-report.json';
await Deno.writeTextFile(reportPath, JSON.stringify(report, null, 2));
console.log(`\n📄 Detailed report saved to: ${reportPath}`);
}
private generateRecommendations(): string[] {
const recommendations: string[] = [];
const avgFPS = this.average(this.results.map(r => r.metrics.averageFPS));
const avgMemory = this.average(this.results.map(r => r.metrics.peakMemoryMB));
const avgSIMD = this.average(this.results.map(r => r.metrics.simdSpeedup));
if (avgFPS < 45) {
recommendations.push('Consider optimizing render pipeline for better FPS');
recommendations.push('Review draw call batching and state management');
}
if (avgMemory > 200) {
recommendations.push('Implement more aggressive memory management');
recommendations.push('Consider texture compression and memory pooling');
}
if (avgSIMD < 2.5) {
recommendations.push('Improve SIMD optimization coverage');
recommendations.push('Profile hot paths for additional SIMD opportunities');
}
const failedTests = this.results.filter(r => !r.passed);
if (failedTests.length > 0) {
recommendations.push(`Focus optimization on failed tests: ${failedTests.map(t => t.testName).join(', ')}`);
}
return recommendations;
}
// Utility functions
private average(numbers: number[]): number {
return numbers.length > 0 ? numbers.reduce((a, b) => a + b, 0) / numbers.length : 0;
}
private sum(numbers: number[]): number {
return numbers.reduce((a, b) => a + b, 0);
}
}
// WebGPU Capability Validation
async function validateWebGPUCapabilities(): Promise<boolean> {
console.log('🔍 Validating WebGPU capabilities...');
// Mock WebGPU detection for Deno environment
const capabilities = {
hasWebGPU: true, // Simulated
hasWASMSIMD: true, // Simulated
hasSharedArrayBuffer: typeof SharedArrayBuffer !== "undefined",
hasTimestampQuery: true, // Simulated
hasTextureCompressionBC: true // Simulated
};
console.log(' WebGPU Available:', capabilities.hasWebGPU ? '✅' : '❌');
console.log(' WASM SIMD:', capabilities.hasWASMSIMD ? '✅' : '❌');
console.log(' SharedArrayBuffer:', capabilities.hasSharedArrayBuffer ? '✅' : '❌');
console.log(' Timestamp Query:', capabilities.hasTimestampQuery ? '✅' : '❌');
console.log(' BC Compression:', capabilities.hasTextureCompressionBC ? '✅' : '❌');
const allCapabilitiesPresent = Object.values(capabilities).every(Boolean);
if (allCapabilitiesPresent) {
console.log('✅ All required capabilities present');
} else {
console.log('❌ Missing required capabilities');
}
return allCapabilitiesPresent;
}
// Main execution
async function main(): Promise<void> {
try {
console.log('🌐 WebGPU GTK4 Performance Validation Suite');
console.log(' Web-native architecture with WASM SIMD optimizations');
console.log(' Target: 3-10x performance improvements over traditional approaches');
console.log('');
// Validate capabilities first
const capabilitiesValid = await validateWebGPUCapabilities();
if (!capabilitiesValid) {
console.log('⚠️ Some capabilities missing, results may not be representative');
}
const validator = new PerformanceValidator();
const results = await validator.runAllBenchmarks();
await validator.generateReport();
// Exit with appropriate code
const passRate = (results.filter(r => r.passed).length / results.length) * 100;
if (passRate === 100) {
console.log('\n🎉 All performance validation tests passed!');
Deno.exit(0);
} else if (passRate >= 80) {
console.log('\n⚠️ Performance validation mostly passed with some issues');
Deno.exit(1);
} else {
console.log('\n❌ Performance validation failed');
Deno.exit(2);
}
} catch (error) {
console.error('❌ Validation suite failed:', error);
Deno.exit(3);
}
}
// Export for module usage
export { PerformanceValidator, type BenchmarkResult, type PerformanceRequirements };
// Run if called directly
if (import.meta.main) {
await main();
}