Memory.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import { Tab } from '../ui/Tab.js';
  2. import { List } from '../ui/List.js';
  3. import { Graph } from '../ui/Graph.js';
  4. import { Item } from '../ui/Item.js';
  5. import { createValueSpan, setText, formatBytes } from '../ui/utils.js';
  6. class Memory extends Tab {
  7. constructor( options = {} ) {
  8. super( 'Memory', options );
  9. const memoryList = new List( 'Name', 'Count', 'Size' );
  10. memoryList.setGridStyle( 'minmax(200px, 2fr) 60px 100px' );
  11. memoryList.domElement.style.minWidth = '300px';
  12. const scrollWrapper = document.createElement( 'div' );
  13. scrollWrapper.className = 'list-scroll-wrapper';
  14. scrollWrapper.appendChild( memoryList.domElement );
  15. this.content.appendChild( scrollWrapper );
  16. // graph
  17. const graphContainer = document.createElement( 'div' );
  18. graphContainer.className = 'graph-container';
  19. const graph = new Graph();
  20. graph.addLine( 'total', 'var( --color-yellow )' );
  21. graphContainer.append( graph.domElement );
  22. // stats
  23. const graphStats = new Item( 'Graph Stats', '', '' );
  24. memoryList.add( graphStats );
  25. const graphItem = new Item( graphContainer );
  26. graphItem.itemRow.childNodes[ 0 ].style.gridColumn = '1 / -1';
  27. graphStats.add( graphItem );
  28. // info
  29. this.memoryStats = new Item( 'Renderer Info', '', createValueSpan() );
  30. this.memoryStats.domElement.firstChild.classList.add( 'no-hover' );
  31. memoryList.add( this.memoryStats );
  32. this.attributes = new Item( 'Attributes', createValueSpan(), createValueSpan() );
  33. this.memoryStats.add( this.attributes );
  34. this.geometries = new Item( 'Geometries', createValueSpan(), 'N/A' );
  35. this.memoryStats.add( this.geometries );
  36. this.indexAttributes = new Item( 'Index Attributes', createValueSpan(), createValueSpan() );
  37. this.memoryStats.add( this.indexAttributes );
  38. this.indirectStorageAttributes = new Item( 'Indirect Storage Attributes', createValueSpan(), createValueSpan() );
  39. this.memoryStats.add( this.indirectStorageAttributes );
  40. this.programs = new Item( 'Programs', createValueSpan(), createValueSpan() );
  41. this.memoryStats.add( this.programs );
  42. this.readbackBuffers = new Item( 'Readback Buffers', createValueSpan(), createValueSpan() );
  43. this.memoryStats.add( this.readbackBuffers );
  44. this.renderTargets = new Item( 'Render Targets', createValueSpan(), 'N/A' );
  45. this.memoryStats.add( this.renderTargets );
  46. this.storageAttributes = new Item( 'Storage Attributes', createValueSpan(), createValueSpan() );
  47. this.memoryStats.add( this.storageAttributes );
  48. this.textures = new Item( 'Textures', createValueSpan(), createValueSpan() );
  49. this.memoryStats.add( this.textures );
  50. this.graph = graph;
  51. }
  52. updateGraph( inspector ) {
  53. const renderer = inspector.getRenderer();
  54. if ( ! renderer ) return;
  55. const memory = renderer.info.memory;
  56. this.graph.addPoint( 'total', memory.total );
  57. if ( this.graph.limit === 0 ) this.graph.limit = 1;
  58. this.graph.update();
  59. }
  60. updateText( inspector ) {
  61. const renderer = inspector.getRenderer();
  62. if ( ! renderer ) return;
  63. const memory = renderer.info.memory;
  64. setText( this.memoryStats.data[ 2 ], formatBytes( memory.total ) );
  65. setText( this.attributes.data[ 1 ], memory.attributes.toString() );
  66. setText( this.attributes.data[ 2 ], formatBytes( memory.attributesSize ) );
  67. setText( this.geometries.data[ 1 ], memory.geometries.toString() );
  68. setText( this.indexAttributes.data[ 1 ], memory.indexAttributes.toString() );
  69. setText( this.indexAttributes.data[ 2 ], formatBytes( memory.indexAttributesSize ) );
  70. setText( this.indirectStorageAttributes.data[ 1 ], memory.indirectStorageAttributes.toString() );
  71. setText( this.indirectStorageAttributes.data[ 2 ], formatBytes( memory.indirectStorageAttributesSize ) );
  72. setText( this.programs.data[ 1 ], memory.programs.toString() );
  73. setText( this.programs.data[ 2 ], formatBytes( memory.programsSize ) );
  74. setText( this.readbackBuffers.data[ 1 ], memory.readbackBuffers.toString() );
  75. setText( this.readbackBuffers.data[ 2 ], formatBytes( memory.readbackBuffersSize ) );
  76. setText( this.renderTargets.data[ 1 ], memory.renderTargets.toString() );
  77. setText( this.storageAttributes.data[ 1 ], memory.storageAttributes.toString() );
  78. setText( this.storageAttributes.data[ 2 ], formatBytes( memory.storageAttributesSize ) );
  79. setText( this.textures.data[ 1 ], memory.textures.toString() );
  80. setText( this.textures.data[ 2 ], formatBytes( memory.texturesSize ) );
  81. }
  82. }
  83. export { Memory };
粤ICP备19079148号