@@ -363,6 +363,83 @@ async def request_adapter_async(self, *, canvas, power_preference=None):
363
363
canvas = canvas , power_preference = power_preference
364
364
) # no-cover
365
365
366
+ def _generate_report (self ):
367
+ """Get a dictionary with info about the internal status of WGPU.
368
+ The structure of the dict is not defined, for the moment. Use print_report().
369
+ """
370
+
371
+ # H: surfaces: WGPUStorageReport, backendType: WGPUBackendType, vulkan: WGPUHubReport, metal: WGPUHubReport, dx12: WGPUHubReport, dx11: WGPUHubReport, gl: WGPUHubReport
372
+ struct = new_struct_p (
373
+ "WGPUGlobalReport *" ,
374
+ # not used: surfaces
375
+ # not used: backendType
376
+ # not used: vulkan
377
+ # not used: metal
378
+ # not used: dx12
379
+ # not used: dx11
380
+ # not used: gl
381
+ )
382
+
383
+ # H: void f(WGPUInstance instance, WGPUGlobalReport* report)
384
+ lib .wgpuGenerateReport (get_wgpu_instance (), struct )
385
+
386
+ report = {}
387
+
388
+ report ["surfaces" ] = {
389
+ "occupied" : struct .surfaces .numOccupied ,
390
+ "vacant" : struct .surfaces .numVacant ,
391
+ "error" : struct .surfaces .numError ,
392
+ "element_size" : struct .surfaces .elementSize ,
393
+ }
394
+ report ["backend_type" ] = struct .backendType # note: could make this a set
395
+ for backend in ("vulkan" , "metal" , "dx12" , "dx11" , "gl" ):
396
+ c_hub_report = getattr (struct , backend )
397
+ report [backend ] = {}
398
+ for key in dir (c_hub_report ):
399
+ c_storage_report = getattr (c_hub_report , key )
400
+ storage_report = {
401
+ "occupied" : c_storage_report .numOccupied ,
402
+ "vacant" : c_storage_report .numVacant ,
403
+ "error" : c_storage_report .numError ,
404
+ "element_size" : c_storage_report .elementSize ,
405
+ }
406
+ # if any(x!=0 for x in storage_report.values()):
407
+ report [backend ][key ] = storage_report
408
+
409
+ return report
410
+
411
+ def print_report (self ):
412
+ def print_line (topic , occupied , vacant , error , el_size ):
413
+ print (
414
+ topic .rjust (20 ),
415
+ str (occupied ).rjust (8 ),
416
+ str (vacant ).rjust (8 ),
417
+ str (error ).rjust (8 ),
418
+ str (el_size ).rjust (8 ),
419
+ )
420
+
421
+ def print_storage_report (topic , d ):
422
+ print_line (topic , d ["occupied" ], d ["vacant" ], d ["error" ], d ["element_size" ])
423
+
424
+ report = self ._generate_report ()
425
+
426
+ print (f"{ self .__class__ .__module__ } .WGPU report:" )
427
+ print ()
428
+ print_line ("" , "Occupied" , "Vacant" , "Error" , "el-size" )
429
+ print ()
430
+ print_storage_report ("surfaces" , report ["surfaces" ])
431
+ for backend in ("vulkan" , "metal" , "dx12" , "dx11" , "gl" ):
432
+ backend_has_stuff = False
433
+ for hub_report in report [backend ].values ():
434
+ report_has_stuff = any (x != 0 for x in hub_report .values ())
435
+ backend_has_stuff |= report_has_stuff
436
+ if backend_has_stuff :
437
+ print_line (f"--- { backend } ---" , "" , "" , "" , "" )
438
+ for key , val in report [backend ].items ():
439
+ print_storage_report (key , val )
440
+ else :
441
+ print_line (f"--- { backend } ---" , "" , "" , "" , "" )
442
+
366
443
367
444
class GPUCanvasContext (base .GPUCanvasContext ):
368
445
def __init__ (self , canvas ):
0 commit comments