@holoscript/core 1.0.0-alpha.2 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/package.json +2 -2
  2. package/src/HoloScript2DParser.js +227 -0
  3. package/src/HoloScript2DParser.ts +5 -0
  4. package/src/HoloScriptCodeParser.js +1102 -0
  5. package/src/HoloScriptCodeParser.ts +145 -20
  6. package/src/HoloScriptDebugger.js +458 -0
  7. package/src/HoloScriptParser.js +338 -0
  8. package/src/HoloScriptPlusParser.js +371 -0
  9. package/src/HoloScriptPlusParser.ts +543 -0
  10. package/src/HoloScriptRuntime.js +1399 -0
  11. package/src/HoloScriptRuntime.test.js +351 -0
  12. package/src/HoloScriptRuntime.ts +17 -3
  13. package/src/HoloScriptTypeChecker.js +356 -0
  14. package/src/__tests__/GraphicsServices.test.js +357 -0
  15. package/src/__tests__/GraphicsServices.test.ts +427 -0
  16. package/src/__tests__/HoloScriptPlusParser.test.js +317 -0
  17. package/src/__tests__/HoloScriptPlusParser.test.ts +392 -0
  18. package/src/__tests__/integration.test.js +336 -0
  19. package/src/__tests__/performance.bench.js +218 -0
  20. package/src/__tests__/type-checker.test.js +60 -0
  21. package/src/__tests__/type-checker.test.ts +73 -0
  22. package/src/index.js +217 -0
  23. package/src/index.ts +158 -18
  24. package/src/interop/Interoperability.js +413 -0
  25. package/src/interop/Interoperability.ts +494 -0
  26. package/src/logger.js +42 -0
  27. package/src/parser/EnhancedParser.js +205 -0
  28. package/src/parser/EnhancedParser.ts +251 -0
  29. package/src/parser/HoloScriptPlusParser.js +928 -0
  30. package/src/parser/HoloScriptPlusParser.ts +1089 -0
  31. package/src/runtime/HoloScriptPlusRuntime.js +674 -0
  32. package/src/runtime/HoloScriptPlusRuntime.ts +861 -0
  33. package/src/runtime/PerformanceTelemetry.js +323 -0
  34. package/src/runtime/PerformanceTelemetry.ts +467 -0
  35. package/src/runtime/RuntimeOptimization.js +361 -0
  36. package/src/runtime/RuntimeOptimization.ts +416 -0
  37. package/src/services/HololandGraphicsPipelineService.js +506 -0
  38. package/src/services/HololandGraphicsPipelineService.ts +662 -0
  39. package/src/services/PlatformPerformanceOptimizer.js +356 -0
  40. package/src/services/PlatformPerformanceOptimizer.ts +503 -0
  41. package/src/state/ReactiveState.js +427 -0
  42. package/src/state/ReactiveState.ts +572 -0
  43. package/src/tools/DeveloperExperience.js +376 -0
  44. package/src/tools/DeveloperExperience.ts +438 -0
  45. package/src/traits/AIDriverTrait.js +322 -0
  46. package/src/traits/AIDriverTrait.test.js +329 -0
  47. package/src/traits/AIDriverTrait.test.ts +357 -0
  48. package/src/traits/AIDriverTrait.ts +474 -0
  49. package/src/traits/LightingTrait.js +313 -0
  50. package/src/traits/LightingTrait.test.js +410 -0
  51. package/src/traits/LightingTrait.test.ts +462 -0
  52. package/src/traits/LightingTrait.ts +505 -0
  53. package/src/traits/MaterialTrait.js +194 -0
  54. package/src/traits/MaterialTrait.test.js +286 -0
  55. package/src/traits/MaterialTrait.test.ts +329 -0
  56. package/src/traits/MaterialTrait.ts +324 -0
  57. package/src/traits/RenderingTrait.js +356 -0
  58. package/src/traits/RenderingTrait.test.js +363 -0
  59. package/src/traits/RenderingTrait.test.ts +427 -0
  60. package/src/traits/RenderingTrait.ts +555 -0
  61. package/src/traits/VRTraitSystem.js +740 -0
  62. package/src/traits/VRTraitSystem.ts +1040 -0
  63. package/src/traits/VoiceInputTrait.js +284 -0
  64. package/src/traits/VoiceInputTrait.test.js +226 -0
  65. package/src/traits/VoiceInputTrait.test.ts +252 -0
  66. package/src/traits/VoiceInputTrait.ts +401 -0
  67. package/src/types/AdvancedTypeSystem.js +226 -0
  68. package/src/types/AdvancedTypeSystem.ts +494 -0
  69. package/src/types/HoloScriptPlus.d.ts +853 -0
  70. package/src/types.js +6 -0
  71. package/src/types.ts +96 -1
  72. package/tsconfig.json +1 -1
  73. package/tsup.config.d.ts +2 -0
  74. package/tsup.config.js +18 -0
@@ -0,0 +1,662 @@
1
+ /**
2
+ * Hololand Graphics Pipeline Service
3
+ *
4
+ * Core service for managing graphics rendering pipeline in Hololand.
5
+ * Integrates HoloScript graphics traits with Hololand's rendering backend.
6
+ *
7
+ * Responsibilities:
8
+ * - Material management and asset pipeline
9
+ * - Light management and shadow mapping
10
+ * - GPU memory optimization
11
+ * - Performance monitoring and profiling
12
+ * - Cross-platform optimization (mobile/VR/desktop)
13
+ */
14
+
15
+ import type { GraphicsConfiguration } from '../HoloScriptPlusParser';
16
+ import type { MaterialTrait } from '../traits/MaterialTrait';
17
+
18
+ // ============================================================================
19
+ // GPU Memory Estimation
20
+ // ============================================================================
21
+
22
+ export interface GPUMemoryEstimate {
23
+ textureMemory: number; // MB
24
+ geometryMemory: number; // MB
25
+ bufferMemory: number; // MB
26
+ estimatedTotal: number; // MB
27
+ budget: number; // MB (allocated limit)
28
+ utilization: number; // percentage
29
+ }
30
+
31
+ // ============================================================================
32
+ // Material Asset Pipeline
33
+ // ============================================================================
34
+
35
+ export interface MaterialAsset {
36
+ id: string;
37
+ name: string;
38
+ material: MaterialTrait;
39
+ shaders: ShaderProgram[];
40
+ textures: TextureAsset[];
41
+ instances: number;
42
+ gpuMemory: number;
43
+ lastUsed: number;
44
+ }
45
+
46
+ export interface TextureAsset {
47
+ id: string;
48
+ path: string;
49
+ format: 'RGBA8' | 'RGB565' | 'BC1' | 'BC3' | 'ASTC' | 'PVRTC';
50
+ width: number;
51
+ height: number;
52
+ mipLevels: number;
53
+ gpuMemory: number;
54
+ loaded: boolean;
55
+ }
56
+
57
+ export interface ShaderProgram {
58
+ id: string;
59
+ name: string;
60
+ vertexShader: string;
61
+ fragmentShader: string;
62
+ uniforms: Record<string, string>;
63
+ compiled: boolean;
64
+ compilationTime: number;
65
+ }
66
+
67
+ // ============================================================================
68
+ // Performance Metrics
69
+ // ============================================================================
70
+
71
+ export interface PerformanceMetrics {
72
+ drawCalls: number;
73
+ trianglesRendered: number;
74
+ gpuFrameTime: number; // ms
75
+ cpuFrameTime: number; // ms
76
+ fps: number;
77
+ gpuMemoryUsed: number; // MB
78
+ textureBinds: number;
79
+ shaderSwitches: number;
80
+ batchCount: number;
81
+ }
82
+
83
+ // ============================================================================
84
+ // Platform Configuration
85
+ // ============================================================================
86
+
87
+ export type Platform = 'mobile' | 'vr' | 'desktop';
88
+
89
+ export interface PlatformConfig {
90
+ platform: Platform;
91
+ maxGPUMemory: number; // MB
92
+ maxDrawCalls: number;
93
+ maxTextureResolution: number;
94
+ targetFPS: number;
95
+ shadowQuality: 'none' | 'low' | 'medium' | 'high';
96
+ textureCompression: 'none' | 'dxt' | 'astc' | 'basis';
97
+ instancingEnabled: boolean;
98
+ maxLights: number;
99
+ maxShadowCasters: number;
100
+ }
101
+
102
+ // ============================================================================
103
+ // Hololand Graphics Pipeline Service
104
+ // ============================================================================
105
+
106
+ export class HololandGraphicsPipelineService {
107
+ private materialCache: Map<string, MaterialAsset> = new Map();
108
+ private textureCache: Map<string, TextureAsset> = new Map();
109
+ private shaderCache: Map<string, ShaderProgram> = new Map();
110
+
111
+ private platformConfig: PlatformConfig;
112
+ private metrics: PerformanceMetrics;
113
+
114
+ // private _memoryBudget: number = 512; // MB default - unused
115
+ private memoryUsed: number = 0;
116
+
117
+ constructor(platform: Platform = 'desktop') {
118
+ this.platformConfig = this.getPlatformConfig(platform);
119
+ this.metrics = this.initializeMetrics();
120
+ }
121
+
122
+ /**
123
+ * Initialize graphics pipeline with configuration
124
+ */
125
+ initialize(config: GraphicsConfiguration): void {
126
+ if (config.material) {
127
+ this.initializeMaterials(config.material);
128
+ }
129
+
130
+ if (config.lighting) {
131
+ this.initializeLighting(config.lighting);
132
+ }
133
+
134
+ if (config.rendering) {
135
+ this.initializeRendering(config.rendering);
136
+ }
137
+ }
138
+
139
+ /**
140
+ * Initialize materials from configuration
141
+ */
142
+ private initializeMaterials(materialConfig: any): void {
143
+ // Create material assets
144
+ const material = this.createMaterialAsset(materialConfig);
145
+ this.materialCache.set(material.id, material);
146
+
147
+ // Pre-compile shaders
148
+ material.shaders.forEach((shader) => {
149
+ this.compileShader(shader);
150
+ });
151
+
152
+ // Load textures
153
+ material.textures.forEach((texture) => {
154
+ this.loadTexture(texture);
155
+ });
156
+ }
157
+
158
+ /**
159
+ * Initialize lighting from configuration
160
+ */
161
+ private initializeLighting(lightingConfig: any): void {
162
+ // Configure shadow mapping
163
+ if (lightingConfig.shadows) {
164
+ this.setupShadowMapping(lightingConfig);
165
+ }
166
+
167
+ // Configure global illumination
168
+ if (lightingConfig.globalIllumination) {
169
+ this.setupGlobalIllumination(lightingConfig.globalIllumination);
170
+ }
171
+ }
172
+
173
+ /**
174
+ * Initialize rendering from configuration
175
+ */
176
+ private initializeRendering(renderingConfig: any): void {
177
+ // Apply quality preset
178
+ if (renderingConfig.quality) {
179
+ this.applyQualityPreset(renderingConfig.quality);
180
+ }
181
+
182
+ // Configure platform-specific settings
183
+ if (renderingConfig.platform) {
184
+ this.platformConfig = this.getPlatformConfig(renderingConfig.platform);
185
+ }
186
+
187
+ // Enable optimizations
188
+ if (renderingConfig.lod !== false) {
189
+ this.enableLOD();
190
+ }
191
+
192
+ if (renderingConfig.culling !== false) {
193
+ this.enableCulling();
194
+ }
195
+
196
+ if (renderingConfig.instancing !== false) {
197
+ this.platformConfig.instancingEnabled = true;
198
+ }
199
+ }
200
+
201
+ /**
202
+ * Create material asset from configuration
203
+ */
204
+ private createMaterialAsset(config: any): MaterialAsset {
205
+ const id = `mat_${Date.now()}_${Math.random()}`;
206
+
207
+ const asset: MaterialAsset = {
208
+ id,
209
+ name: config.name || 'Material',
210
+ material: null as any, // Would be actual MaterialTrait
211
+ shaders: this.generateShaders(config),
212
+ textures: this.loadTexturesFromConfig(config),
213
+ instances: 0,
214
+ gpuMemory: 0,
215
+ lastUsed: Date.now(),
216
+ };
217
+
218
+ // Estimate GPU memory
219
+ asset.gpuMemory = this.estimateMaterialMemory(asset);
220
+ this.memoryUsed += asset.gpuMemory;
221
+
222
+ return asset;
223
+ }
224
+
225
+ /**
226
+ * Generate shaders from material configuration
227
+ */
228
+ private generateShaders(config: any): ShaderProgram[] {
229
+ const shaders: ShaderProgram[] = [];
230
+
231
+ // Generate PBR shader
232
+ if (config.type === 'pbr' || config.pbr) {
233
+ shaders.push(this.generatePBRShader(config));
234
+ }
235
+
236
+ return shaders;
237
+ }
238
+
239
+ /**
240
+ * Generate PBR shader program
241
+ */
242
+ private generatePBRShader(_config: any): ShaderProgram {
243
+ const vertexShader = `
244
+ #version 300 es
245
+ precision highp float;
246
+
247
+ in vec3 aPosition;
248
+ in vec3 aNormal;
249
+ in vec2 aTexCoord;
250
+ in vec3 aTangent;
251
+
252
+ uniform mat4 uMatrix;
253
+ uniform mat4 uNormalMatrix;
254
+ uniform mat4 uProjectionMatrix;
255
+
256
+ out vec3 vPosition;
257
+ out vec3 vNormal;
258
+ out vec2 vTexCoord;
259
+ out mat3 vTBN;
260
+
261
+ void main() {
262
+ vPosition = (uMatrix * vec4(aPosition, 1.0)).xyz;
263
+ vNormal = normalize((uNormalMatrix * vec4(aNormal, 0.0)).xyz);
264
+ vTexCoord = aTexCoord;
265
+
266
+ vec3 T = normalize((uNormalMatrix * vec4(aTangent, 0.0)).xyz);
267
+ vec3 B = cross(vNormal, T);
268
+ vTBN = mat3(T, B, vNormal);
269
+
270
+ gl_Position = uProjectionMatrix * uMatrix * vec4(aPosition, 1.0);
271
+ }
272
+ `;
273
+
274
+ const fragmentShader = `
275
+ #version 300 es
276
+ precision highp float;
277
+
278
+ in vec3 vPosition;
279
+ in vec3 vNormal;
280
+ in vec2 vTexCoord;
281
+ in mat3 vTBN;
282
+
283
+ uniform sampler2D uBaseColorMap;
284
+ uniform sampler2D uNormalMap;
285
+ uniform sampler2D uRoughnessMap;
286
+ uniform sampler2D uMetallicMap;
287
+ uniform sampler2D uAOMap;
288
+
289
+ uniform vec3 uViewPos;
290
+ uniform float uMetallic;
291
+ uniform float uRoughness;
292
+
293
+ out vec4 FragColor;
294
+
295
+ const float PI = 3.14159265359;
296
+
297
+ vec3 fresnelSchlick(float cosTheta, vec3 F0) {
298
+ return F0 + (1.0 - F0) * pow(clamp(1.0 - cosTheta, 0.0, 1.0), 5.0);
299
+ }
300
+
301
+ void main() {
302
+ vec3 baseColor = texture(uBaseColorMap, vTexCoord).rgb;
303
+ vec3 normal = normalize(vTBN * (texture(uNormalMap, vTexCoord).rgb * 2.0 - 1.0));
304
+ float roughness = texture(uRoughnessMap, vTexCoord).r;
305
+ float metallic = texture(uMetallicMap, vTexCoord).r;
306
+ float ao = texture(uAOMap, vTexCoord).r;
307
+
308
+ vec3 N = normalize(normal);
309
+ vec3 V = normalize(uViewPos - vPosition);
310
+
311
+ vec3 F0 = vec3(0.04);
312
+ F0 = mix(F0, baseColor, metallic);
313
+
314
+ // Simplified lighting (full PBR in production)
315
+ vec3 lightDir = normalize(vec3(0.5, 1.0, 0.5));
316
+ float NdotL = max(dot(N, lightDir), 0.0);
317
+
318
+ vec3 result = baseColor * NdotL * ao;
319
+
320
+ // Tone mapping
321
+ result = result / (result + vec3(1.0));
322
+ result = pow(result, vec3(1.0 / 2.2));
323
+
324
+ FragColor = vec4(result, 1.0);
325
+ }
326
+ `;
327
+
328
+ return {
329
+ id: `shader_pbr_${Date.now()}`,
330
+ name: 'PBRShader',
331
+ vertexShader,
332
+ fragmentShader,
333
+ uniforms: {
334
+ uMatrix: 'mat4',
335
+ uNormalMatrix: 'mat4',
336
+ uProjectionMatrix: 'mat4',
337
+ uViewPos: 'vec3',
338
+ uMetallic: 'float',
339
+ uRoughness: 'float',
340
+ uBaseColorMap: 'sampler2D',
341
+ uNormalMap: 'sampler2D',
342
+ uRoughnessMap: 'sampler2D',
343
+ uMetallicMap: 'sampler2D',
344
+ uAOMap: 'sampler2D',
345
+ },
346
+ compiled: false,
347
+ compilationTime: 0,
348
+ };
349
+ }
350
+
351
+ /**
352
+ * Load textures from configuration
353
+ */
354
+ private loadTexturesFromConfig(config: any): TextureAsset[] {
355
+ const textures: TextureAsset[] = [];
356
+
357
+ if (config.textures) {
358
+ config.textures.forEach((tex: any) => {
359
+ textures.push({
360
+ id: `tex_${Date.now()}_${Math.random()}`,
361
+ path: tex.path,
362
+ format: this.selectTextureFormat(config.compression),
363
+ width: 2048,
364
+ height: 2048,
365
+ mipLevels: 8,
366
+ gpuMemory: this.estimateTextureMemory(2048, 2048, this.selectTextureFormat(config.compression)),
367
+ loaded: false,
368
+ });
369
+ });
370
+ }
371
+
372
+ return textures;
373
+ }
374
+
375
+ /**
376
+ * Select appropriate texture format based on compression type
377
+ */
378
+ private selectTextureFormat(compression?: string): TextureAsset['format'] {
379
+ switch (compression) {
380
+ case 'dxt':
381
+ return 'BC3';
382
+ case 'astc':
383
+ return 'ASTC';
384
+ case 'basis':
385
+ return 'PVRTC';
386
+ default:
387
+ return 'RGBA8';
388
+ }
389
+ }
390
+
391
+ /**
392
+ * Estimate texture memory usage
393
+ */
394
+ private estimateTextureMemory(width: number, height: number, format: TextureAsset['format']): number {
395
+ const pixels = width * height;
396
+ let bytesPerPixel = 4; // RGBA8
397
+
398
+ switch (format) {
399
+ case 'RGB565':
400
+ bytesPerPixel = 2;
401
+ break;
402
+ case 'BC1':
403
+ case 'BC3':
404
+ case 'ASTC':
405
+ bytesPerPixel = 0.5; // Compressed
406
+ break;
407
+ case 'PVRTC':
408
+ bytesPerPixel = 0.25; // Highly compressed
409
+ break;
410
+ }
411
+
412
+ // Account for mipmaps (roughly 1.33x base size)
413
+ return (pixels * bytesPerPixel * 1.33) / (1024 * 1024);
414
+ }
415
+
416
+ /**
417
+ * Estimate material GPU memory
418
+ */
419
+ private estimateMaterialMemory(asset: MaterialAsset): number {
420
+ let total = 0;
421
+
422
+ // Shader memory (typically negligible, but count)
423
+ total += 0.1; // 100KB per shader
424
+
425
+ // Texture memory
426
+ asset.textures.forEach((tex) => {
427
+ total += tex.gpuMemory;
428
+ });
429
+
430
+ return total;
431
+ }
432
+
433
+ /**
434
+ * Compile shader program
435
+ */
436
+ private compileShader(shader: ShaderProgram): void {
437
+ const start = performance.now();
438
+
439
+ // In real implementation, this would compile to WebGL/WebGPU
440
+ // For now, just mark as compiled
441
+ shader.compiled = true;
442
+ shader.compilationTime = performance.now() - start;
443
+
444
+ this.shaderCache.set(shader.id, shader);
445
+ }
446
+
447
+ /**
448
+ * Load texture into GPU memory
449
+ */
450
+ private loadTexture(texture: TextureAsset): void {
451
+ // In real implementation, this would load from disk/network
452
+ // For now, just mark as loaded
453
+ texture.loaded = true;
454
+ this.textureCache.set(texture.id, texture);
455
+ }
456
+
457
+ /**
458
+ * Setup shadow mapping
459
+ */
460
+ private setupShadowMapping(_config: any): void {
461
+ // Configure shadow map resolution and filtering
462
+ // const shadowQuality = this.platformConfig.shadowQuality;
463
+ // const _shadowResolution = this.shadowResolutionForQuality(shadowQuality);
464
+
465
+ // Create shadow map textures
466
+ // This would allocate GPU memory for shadow maps
467
+ }
468
+
469
+ /**
470
+ * Get shadow map resolution for quality level
471
+ */
472
+ // private shadowResolutionForQuality(quality: string): number {
473
+ // switch (quality) {
474
+ // case 'none':
475
+ // return 0;
476
+ // case 'low':
477
+ // return 512;
478
+ // case 'medium':
479
+ // return 1024;
480
+ // case 'high':
481
+ // return 2048;
482
+ // default:
483
+ // return 1024;
484
+ // }
485
+ // }
486
+
487
+ /**
488
+ * Setup global illumination
489
+ */
490
+ private setupGlobalIllumination(__config: any): void {
491
+ // Create light probes for indirect lighting
492
+ // const _probeCount = __config.probes || 16;
493
+
494
+ // Allocate GPU memory for probes
495
+ // Each probe stores 6 faces of cubemap
496
+ }
497
+
498
+ /**
499
+ * Apply quality preset
500
+ */
501
+ private applyQualityPreset(quality: string): void {
502
+ switch (quality) {
503
+ case 'low':
504
+ this.platformConfig.maxTextureResolution = 512;
505
+ this.platformConfig.shadowQuality = 'none';
506
+ this.platformConfig.targetFPS = 30;
507
+ break;
508
+
509
+ case 'medium':
510
+ this.platformConfig.maxTextureResolution = 1024;
511
+ this.platformConfig.shadowQuality = 'low';
512
+ this.platformConfig.targetFPS = 60;
513
+ break;
514
+
515
+ case 'high':
516
+ this.platformConfig.maxTextureResolution = 2048;
517
+ this.platformConfig.shadowQuality = 'medium';
518
+ this.platformConfig.targetFPS = 60;
519
+ break;
520
+
521
+ case 'ultra':
522
+ this.platformConfig.maxTextureResolution = 4096;
523
+ this.platformConfig.shadowQuality = 'high';
524
+ this.platformConfig.targetFPS = 120;
525
+ break;
526
+ }
527
+ }
528
+
529
+ /**
530
+ * Enable LOD system
531
+ */
532
+ private enableLOD(): void {
533
+ // Configure automatic LOD switching based on screen coverage
534
+ }
535
+
536
+ /**
537
+ * Enable culling
538
+ */
539
+ private enableCulling(): void {
540
+ // Enable frustum culling and occlusion culling
541
+ }
542
+
543
+ /**
544
+ * Get platform-specific configuration
545
+ */
546
+ private getPlatformConfig(platform: Platform): PlatformConfig {
547
+ switch (platform) {
548
+ case 'mobile':
549
+ return {
550
+ platform: 'mobile',
551
+ maxGPUMemory: 256,
552
+ maxDrawCalls: 200,
553
+ maxTextureResolution: 512,
554
+ targetFPS: 30,
555
+ shadowQuality: 'none',
556
+ textureCompression: 'astc',
557
+ instancingEnabled: true,
558
+ maxLights: 2,
559
+ maxShadowCasters: 0,
560
+ };
561
+
562
+ case 'vr':
563
+ return {
564
+ platform: 'vr',
565
+ maxGPUMemory: 512,
566
+ maxDrawCalls: 500,
567
+ maxTextureResolution: 2048,
568
+ targetFPS: 90,
569
+ shadowQuality: 'low',
570
+ textureCompression: 'basis',
571
+ instancingEnabled: true,
572
+ maxLights: 4,
573
+ maxShadowCasters: 2,
574
+ };
575
+
576
+ case 'desktop':
577
+ return {
578
+ platform: 'desktop',
579
+ maxGPUMemory: 2048,
580
+ maxDrawCalls: 2000,
581
+ maxTextureResolution: 4096,
582
+ targetFPS: 120,
583
+ shadowQuality: 'high',
584
+ textureCompression: 'none',
585
+ instancingEnabled: true,
586
+ maxLights: 8,
587
+ maxShadowCasters: 4,
588
+ };
589
+ }
590
+ }
591
+
592
+ /**
593
+ * Initialize performance metrics
594
+ */
595
+ private initializeMetrics(): PerformanceMetrics {
596
+ return {
597
+ drawCalls: 0,
598
+ trianglesRendered: 0,
599
+ gpuFrameTime: 0,
600
+ cpuFrameTime: 0,
601
+ fps: 60,
602
+ gpuMemoryUsed: 0,
603
+ textureBinds: 0,
604
+ shaderSwitches: 0,
605
+ batchCount: 0,
606
+ };
607
+ }
608
+
609
+ /**
610
+ * Get current GPU memory estimate
611
+ */
612
+ getGPUMemoryEstimate(): GPUMemoryEstimate {
613
+ let textureMemory = 0;
614
+ let geometryMemory = 0;
615
+ let bufferMemory = 0;
616
+
617
+ this.textureCache.forEach((tex) => {
618
+ if (tex.loaded) {
619
+ textureMemory += tex.gpuMemory;
620
+ }
621
+ });
622
+
623
+ this.materialCache.forEach((mat) => {
624
+ geometryMemory += mat.gpuMemory;
625
+ });
626
+
627
+ const total = textureMemory + geometryMemory + bufferMemory;
628
+
629
+ return {
630
+ textureMemory,
631
+ geometryMemory,
632
+ bufferMemory,
633
+ estimatedTotal: total,
634
+ budget: this.platformConfig.maxGPUMemory,
635
+ utilization: (total / this.platformConfig.maxGPUMemory) * 100,
636
+ };
637
+ }
638
+
639
+ /**
640
+ * Get performance metrics
641
+ */
642
+ getPerformanceMetrics(): PerformanceMetrics {
643
+ return { ...this.metrics };
644
+ }
645
+
646
+ /**
647
+ * Set memory budget
648
+ */
649
+ setMemoryBudget(budget: number): void {
650
+ // this._memoryBudget = budget; // field removed
651
+ this.platformConfig.maxGPUMemory = budget;
652
+ }
653
+
654
+ /**
655
+ * Optimize for specific platform
656
+ */
657
+ optimizePlatform(platform: Platform): void {
658
+ this.platformConfig = this.getPlatformConfig(platform);
659
+ }
660
+ }
661
+
662
+ export default HololandGraphicsPipelineService;