@playcanvas/inspector 0.4.0 → 0.6.0
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.
- package/README.md +176 -3
- package/package.json +8 -6
- package/src/asset-view.js +66 -3
- package/src/camera-view.js +1 -1
- package/src/copy-json.js +48 -9
- package/src/describe.js +1 -1
- package/src/frame-graph-view.js +4 -4
- package/src/image-capture.js +387 -0
- package/src/inspector.js +700 -57
- package/src/layer-view.js +235 -0
- package/src/list-view.js +2 -0
- package/src/log-capture.js +225 -0
- package/src/material-view.js +1 -1
- package/src/mcp-tools.js +1149 -0
- package/src/memory-view.js +60 -4
- package/src/mesh-view.js +51 -2
- package/src/perf-copy.js +1 -1
- package/src/physics-view.js +2 -2
- package/src/ref-registry.js +136 -0
- package/src/render-target-view.js +86 -9
- package/src/shader-view.js +33 -2
- package/src/snapshot-view.js +268 -0
- package/src/styles.js +283 -0
- package/src/texture-view.js +2 -2
- package/src/treemap-view.js +837 -0
- package/types/asset-view.d.ts +10 -0
- package/types/image-capture.d.ts +136 -0
- package/types/inspector.d.ts +291 -11
- package/types/layer-view.d.ts +80 -0
- package/types/log-capture.d.ts +104 -0
- package/types/mcp-tools.d.ts +855 -0
- package/types/memory-view.d.ts +11 -0
- package/types/mesh-view.d.ts +13 -0
- package/types/perf-copy.d.ts +22 -0
- package/types/ref-registry.d.ts +75 -0
- package/types/render-target-view.d.ts +17 -4
- package/types/shader-view.d.ts +12 -0
- package/types/snapshot-view.d.ts +166 -0
- package/types/texture-view.d.ts +12 -1
- package/types/treemap-view.d.ts +379 -0
package/src/memory-view.js
CHANGED
|
@@ -4,10 +4,10 @@ import {
|
|
|
4
4
|
|
|
5
5
|
import { describeValue, isUniformBuffer } from './describe.js';
|
|
6
6
|
import { collectMeshInstances } from './instance-survey.js';
|
|
7
|
-
import { formatBytes, makeSection, makeUsageSection, push, read, reflectRows } from './model.js';
|
|
7
|
+
import { formatBytes, formatName, makeSection, makeUsageSection, push, read, reflectRows } from './model.js';
|
|
8
8
|
import { vertexFormatValue } from './node-model.js';
|
|
9
9
|
import { formatUniformBuffer } from './shader-view.js';
|
|
10
|
-
import { collectTextures } from './texture-view.js';
|
|
10
|
+
import { attachmentTargets, collectTextures, shapeText } from './texture-view.js';
|
|
11
11
|
|
|
12
12
|
/** @import { AppBase } from 'playcanvas' */
|
|
13
13
|
/** @import { UniformBuffer } from 'playcanvas' */
|
|
@@ -18,6 +18,8 @@ import { collectTextures } from './texture-view.js';
|
|
|
18
18
|
/** @import { Described } from './describe.js' */
|
|
19
19
|
/** @import { ListRow } from './list-view.js' */
|
|
20
20
|
/** @import { PropertySection } from './model.js' */
|
|
21
|
+
/** @import { SnapshotContent } from './snapshot-view.js' */
|
|
22
|
+
/** @import { SnapshotItem } from './treemap-view.js' */
|
|
21
23
|
|
|
22
24
|
/**
|
|
23
25
|
* @typedef {VertexBuffer|IndexBuffer|UniformBuffer|StorageBuffer} Buffer
|
|
@@ -325,7 +327,7 @@ function bufferRow(buffer, users) {
|
|
|
325
327
|
title,
|
|
326
328
|
cells: [
|
|
327
329
|
{ text: name, cls: 'pci-cell-name' }, { text: notes.join(' · '), cls: 'pci-cell-info' },
|
|
328
|
-
{ text: size, cls: 'pci-cell-info pci-cell-right' }
|
|
330
|
+
{ text: size, cls: 'pci-cell-info pci-cell-right', field: 'size' }
|
|
329
331
|
]
|
|
330
332
|
};
|
|
331
333
|
}
|
|
@@ -436,6 +438,60 @@ function memoryRows(device, owners) {
|
|
|
436
438
|
return rows;
|
|
437
439
|
}
|
|
438
440
|
|
|
441
|
+
/**
|
|
442
|
+
* What the Memory tab measures in a snapshot: every texture and buffer on the device, a group per
|
|
443
|
+
* kind. Textures are split by whether they are attached to a render target, and each buffer is
|
|
444
|
+
* named after what uses it, as in the list. The per-draw uniform pool counts as one.
|
|
445
|
+
*
|
|
446
|
+
* @param {GraphicsDevice} device - The device.
|
|
447
|
+
* @param {Map<Buffer, BufferOwner[]>} owners - The owners of each buffer.
|
|
448
|
+
* @returns {SnapshotContent} The textures and buffers measured.
|
|
449
|
+
*/
|
|
450
|
+
function memorySnapshot(device, owners) {
|
|
451
|
+
/** @type {SnapshotItem[]} */
|
|
452
|
+
const items = [];
|
|
453
|
+
const attached = attachmentTargets(device);
|
|
454
|
+
for (const texture of collectTextures(device)) {
|
|
455
|
+
items.push({
|
|
456
|
+
key: `texture${texture.id}`,
|
|
457
|
+
target: new WeakRef(texture),
|
|
458
|
+
group: ['Textures', attached.has(texture) ? 'render target attachments' : 'other textures'],
|
|
459
|
+
name: texture.name || '(unnamed)',
|
|
460
|
+
size: texture.gpuSize,
|
|
461
|
+
info: `${shapeText(texture)} ${formatName(texture.format)}${texture.mipmaps ? `, ${texture.numLevels} mip levels` : ''}`
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
const titles = Object.fromEntries(BUFFER_GROUPS);
|
|
465
|
+
let persistent = 0;
|
|
466
|
+
for (const buffer of collectBuffers(device)) {
|
|
467
|
+
const kind = bufferKind(buffer);
|
|
468
|
+
const users = owners.get(buffer);
|
|
469
|
+
const bytes = bufferBytes(buffer);
|
|
470
|
+
if (kind === 'uniform') persistent += bytes;
|
|
471
|
+
const content = contentText(buffer);
|
|
472
|
+
items.push({
|
|
473
|
+
key: `buffer${idOf(buffer)}`,
|
|
474
|
+
target: new WeakRef(buffer),
|
|
475
|
+
group: [titles[kind]],
|
|
476
|
+
name: bufferName(users),
|
|
477
|
+
size: bytes,
|
|
478
|
+
info: [content, users ? `${users[0].role} of ${users[0].label}${users.length > 1 ? `, ${users.length} users` : ''}` : 'owner not found'].filter(Boolean).join(' · ')
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
const pool = /** @type {any} */ (device).dynamicBuffers;
|
|
482
|
+
if (pool?.bufferCount) {
|
|
483
|
+
const vram = /** @type {any} */ (device)._vram ?? {};
|
|
484
|
+
items.push({
|
|
485
|
+
key: 'uniform-pool',
|
|
486
|
+
group: [titles.uniform],
|
|
487
|
+
name: 'per-draw uniform pool',
|
|
488
|
+
size: Math.max(0, (vram.ub ?? 0) - persistent),
|
|
489
|
+
info: `${plural(pool.bufferCount, 'buffer')} the uniforms set for each draw are written into, every frame`
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
return { measure: 'GPU memory of the textures and buffers on the device', items, note: 'The device caches are counted, not measured, and are left out.' };
|
|
493
|
+
}
|
|
494
|
+
|
|
439
495
|
/**
|
|
440
496
|
* Everything the property view shows for a buffer: its size and layout, what it was found to
|
|
441
497
|
* belong to (linked), and every other public property.
|
|
@@ -498,5 +554,5 @@ function ownersSection(buffer, app) {
|
|
|
498
554
|
}
|
|
499
555
|
|
|
500
556
|
export {
|
|
501
|
-
bufferKind, bufferOwners, buildBufferModel, collectBuffers, idOf, KIND_NAMES, memoryRows, nodeLabel, videoMemory
|
|
557
|
+
bufferKind, bufferOwners, buildBufferModel, collectBuffers, idOf, KIND_NAMES, memoryRows, memorySnapshot, nodeLabel, videoMemory
|
|
502
558
|
};
|
package/src/mesh-view.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Mesh, VertexBuffer } from 'playcanvas';
|
|
2
2
|
|
|
3
|
+
import { containerParts } from './asset-view.js';
|
|
3
4
|
import { describeValue } from './describe.js';
|
|
4
5
|
import { collectMeshInstances } from './instance-survey.js';
|
|
5
6
|
import { nodeLabel } from './memory-view.js';
|
|
@@ -8,10 +9,13 @@ import { meshInstanceRows, meshRows } from './node-model.js';
|
|
|
8
9
|
|
|
9
10
|
/** @import { AppBase } from 'playcanvas' */
|
|
10
11
|
/** @import { Asset } from 'playcanvas' */
|
|
12
|
+
/** @import { AssetRegistry } from 'playcanvas' */
|
|
11
13
|
/** @import { GraphNode } from 'playcanvas' */
|
|
12
14
|
/** @import { MeshInstance } from 'playcanvas' */
|
|
13
15
|
/** @import { ListRow } from './list-view.js' */
|
|
14
16
|
/** @import { PropertySection } from './model.js' */
|
|
17
|
+
/** @import { SnapshotContent } from './snapshot-view.js' */
|
|
18
|
+
/** @import { SnapshotItem } from './treemap-view.js' */
|
|
15
19
|
|
|
16
20
|
/**
|
|
17
21
|
* Something a mesh was found to be used by.
|
|
@@ -164,7 +168,7 @@ function meshListRows(survey) {
|
|
|
164
168
|
if (mesh.skin) cells.push({ text: 'skinned', cls: 'pci-cell-tag pci-cell-tag-info' });
|
|
165
169
|
if (mesh.morph) cells.push({ text: 'morph', cls: 'pci-cell-tag pci-cell-tag-info' });
|
|
166
170
|
cells.push({ text: `${geometryText(mesh)} · ${instances} instance${instances === 1 ? '' : 's'}`, cls: 'pci-cell-info' });
|
|
167
|
-
cells.push({ text: formatBytes(meshBytes(mesh)), cls: 'pci-cell-info pci-cell-right' });
|
|
171
|
+
cells.push({ text: formatBytes(meshBytes(mesh)), cls: 'pci-cell-info pci-cell-right', field: 'size' });
|
|
168
172
|
const title = `Mesh #${mesh.id}\n${geometryText(mesh)}, ${formatBytes(meshBytes(mesh))}\n` +
|
|
169
173
|
`${instances ? `drawn by ${instances} mesh instance${instances === 1 ? '' : 's'}` : 'drawn by no mesh instance'}` +
|
|
170
174
|
`${users.length > instances ? `, held by ${users[users.length - 1].label}` : ''}`;
|
|
@@ -181,6 +185,51 @@ function meshListRows(survey) {
|
|
|
181
185
|
});
|
|
182
186
|
}
|
|
183
187
|
|
|
188
|
+
/**
|
|
189
|
+
* @param {string} role - How a mesh was found, such as 'render component' or 'drawn on "World"'.
|
|
190
|
+
* @returns {string} The group a snapshot draws such meshes in.
|
|
191
|
+
*/
|
|
192
|
+
function roleGroup(role) {
|
|
193
|
+
const layer = /^drawn on (.*)$/.exec(role);
|
|
194
|
+
if (layer) return `Layer ${layer[1]}`;
|
|
195
|
+
return `${role[0].toUpperCase()}${role.slice(1)}${role.endsWith('lines') ? '' : 's'}`;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* What the Meshes tab measures in a snapshot: the vertex and index buffers of every mesh found, a
|
|
200
|
+
* group per asset holding the meshes, and for meshes of no asset, a group per way they were found.
|
|
201
|
+
* A model file loads as a container with a render asset per mesh, so meshes are grouped by the
|
|
202
|
+
* container's file rather than by those.
|
|
203
|
+
*
|
|
204
|
+
* @param {MeshSurvey} survey - The meshes found.
|
|
205
|
+
* @param {AssetRegistry|null} registry - The registry, to find the containers.
|
|
206
|
+
* @returns {SnapshotContent} The meshes measured.
|
|
207
|
+
*/
|
|
208
|
+
function meshSnapshot(survey, registry) {
|
|
209
|
+
const { parentOf } = containerParts(registry);
|
|
210
|
+
/** @type {SnapshotItem[]} */
|
|
211
|
+
const items = [];
|
|
212
|
+
for (const [mesh, users] of survey.users) {
|
|
213
|
+
const holder = users.find(user => user.role === 'render asset' || user.role === 'model asset');
|
|
214
|
+
const asset = /** @type {Asset|undefined} */ (holder?.target);
|
|
215
|
+
const file = asset ? (parentOf.get(asset) ?? asset) : null;
|
|
216
|
+
const size = meshBytes(mesh);
|
|
217
|
+
const vertices = mesh.vertexBuffer?.numBytes ?? 0;
|
|
218
|
+
const instances = instanceCount(users);
|
|
219
|
+
items.push({
|
|
220
|
+
key: `mesh${mesh.id}`,
|
|
221
|
+
target: new WeakRef(mesh),
|
|
222
|
+
group: [file ? `Asset "${file.name}"` : users[0] ? roleGroup(users[0].role) : 'Other'],
|
|
223
|
+
name: meshName(mesh, users),
|
|
224
|
+
size,
|
|
225
|
+
info: `Mesh #${mesh.id} · ${geometryText(mesh)} · vertices ${formatBytes(vertices)}, indices ${formatBytes(size - vertices)} · ` +
|
|
226
|
+
`${instances} instance${instances === 1 ? '' : 's'}`
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
const note = survey.unaccounted ? `${survey.unaccounted} vertex buffer${survey.unaccounted === 1 ? '' : 's'} of no mesh found ${survey.unaccounted === 1 ? 'is' : 'are'} left out; the Memory tab counts them.` : '';
|
|
230
|
+
return { measure: 'Bytes of the vertex and index buffers of each mesh', items, note };
|
|
231
|
+
}
|
|
232
|
+
|
|
184
233
|
/**
|
|
185
234
|
* The line above the list: how many meshes were found, and whether any vertex buffer on the device
|
|
186
235
|
* belongs to none of them.
|
|
@@ -233,4 +282,4 @@ function buildMeshModel(mesh, ctx) {
|
|
|
233
282
|
return [general, usage];
|
|
234
283
|
}
|
|
235
284
|
|
|
236
|
-
export { buildMeshModel, meshBytes, meshListRows, meshNote, surveyMeshes };
|
|
285
|
+
export { buildMeshModel, meshBytes, meshListRows, meshNote, meshSnapshot, surveyMeshes };
|
package/src/perf-copy.js
CHANGED
package/src/physics-view.js
CHANGED
|
@@ -103,7 +103,7 @@ function bodyRows(app, hidden, drawing) {
|
|
|
103
103
|
{ text: rigidbody.type, cls: 'pci-cell-tag pci-cell-tag-info' },
|
|
104
104
|
{ text: shapeText(entity.collision), cls: 'pci-cell-info' },
|
|
105
105
|
{ text: dynamic ? `${formatNumber(rigidbody.mass)} kg` : '', cls: 'pci-cell-info' },
|
|
106
|
-
{ text: `${state}${speed}`, cls: 'pci-cell-info pci-cell-right' }
|
|
106
|
+
{ text: `${state}${speed}`, cls: 'pci-cell-info pci-cell-right', field: 'state' }
|
|
107
107
|
]
|
|
108
108
|
};
|
|
109
109
|
});
|
|
@@ -151,7 +151,7 @@ function jointRows(app) {
|
|
|
151
151
|
{ text: '↔', cls: 'pci-cell-info' },
|
|
152
152
|
{ text: b ? b.name : 'world', cls: 'pci-cell-info', target: b ?? undefined },
|
|
153
153
|
{ text: flags, cls: 'pci-cell-info' },
|
|
154
|
-
{ text: broken ? 'broken' : (joint.enabled ? 'active' : 'disabled'), cls: 'pci-cell-info pci-cell-right' }
|
|
154
|
+
{ text: broken ? 'broken' : (joint.enabled ? 'active' : 'disabled'), cls: 'pci-cell-info pci-cell-right', field: 'state' }
|
|
155
155
|
]
|
|
156
156
|
};
|
|
157
157
|
});
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { Asset, Component, FramePass, GraphNode, Layer, Material, Mesh, MeshInstance, RenderTarget, Shader, Texture } from 'playcanvas';
|
|
2
|
+
|
|
3
|
+
import { LayerStepSelection } from './frame-graph-view.js';
|
|
4
|
+
import { isScriptClass } from './script-view.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param {object} obj - An object.
|
|
8
|
+
* @returns {string} The kind its id is prefixed with, so an id says what it stands for.
|
|
9
|
+
*/
|
|
10
|
+
function kindOf(obj) {
|
|
11
|
+
if (obj instanceof GraphNode) return 'node';
|
|
12
|
+
if (obj instanceof Component) return 'component';
|
|
13
|
+
if (obj instanceof MeshInstance) return 'meshInstance';
|
|
14
|
+
if (obj instanceof Mesh) return 'mesh';
|
|
15
|
+
if (obj instanceof Material) return 'material';
|
|
16
|
+
if (obj instanceof Shader) return 'shader';
|
|
17
|
+
if (obj instanceof Texture) return 'texture';
|
|
18
|
+
if (obj instanceof RenderTarget) return 'renderTarget';
|
|
19
|
+
if (obj instanceof FramePass) return 'pass';
|
|
20
|
+
if (obj instanceof LayerStepSelection) return 'step';
|
|
21
|
+
if (obj instanceof Asset) return 'asset';
|
|
22
|
+
if (obj instanceof Layer) return 'layer';
|
|
23
|
+
if (isScriptClass(obj)) return 'script';
|
|
24
|
+
return 'object';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Gives objects of the app ids that stay the same for as long as the registry lives, and looks
|
|
29
|
+
* them up again by id, without keeping them alive: an object the app lets go of is collected as
|
|
30
|
+
* usual, and its id then finds nothing.
|
|
31
|
+
*
|
|
32
|
+
* @ignore
|
|
33
|
+
*/
|
|
34
|
+
class RefRegistry {
|
|
35
|
+
/**
|
|
36
|
+
* @type {WeakMap<object, string>}
|
|
37
|
+
* @private
|
|
38
|
+
*/
|
|
39
|
+
_ids = new WeakMap();
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @type {Map<string, WeakRef<object>>}
|
|
43
|
+
* @private
|
|
44
|
+
*/
|
|
45
|
+
_objects = new Map();
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @type {number}
|
|
49
|
+
* @private
|
|
50
|
+
*/
|
|
51
|
+
_next = 1;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The number of ids at which the ids of collected objects are next dropped.
|
|
55
|
+
*
|
|
56
|
+
* @type {number}
|
|
57
|
+
* @private
|
|
58
|
+
*/
|
|
59
|
+
_sweepAt = 1024;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The ids given by key, see {@link RefRegistry#keyedId}, and how each finds its object.
|
|
63
|
+
*
|
|
64
|
+
* @type {Map<string, string>}
|
|
65
|
+
* @private
|
|
66
|
+
*/
|
|
67
|
+
_keyIds = new Map();
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @type {Map<string, () => object|null>}
|
|
71
|
+
* @private
|
|
72
|
+
*/
|
|
73
|
+
_resolvers = new Map();
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* @param {object} obj - An object or a function, such as a script class.
|
|
77
|
+
* @returns {string} Its id, such as `material:12`.
|
|
78
|
+
*/
|
|
79
|
+
idOf(obj) {
|
|
80
|
+
let id = this._ids.get(obj);
|
|
81
|
+
if (!id) {
|
|
82
|
+
id = `${kindOf(obj)}:${this._next++}`;
|
|
83
|
+
this._ids.set(obj, id);
|
|
84
|
+
this._objects.set(id, new WeakRef(obj));
|
|
85
|
+
if (this._objects.size >= this._sweepAt) this._sweep();
|
|
86
|
+
}
|
|
87
|
+
return id;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Gives an id to whatever stands at a stable key, rather than to one object, for things the
|
|
92
|
+
* app rebuilds every frame, such as some passes of the frame graph. The id then finds the
|
|
93
|
+
* object standing at the key when it is looked up.
|
|
94
|
+
*
|
|
95
|
+
* @param {string} kind - The kind the id is prefixed with.
|
|
96
|
+
* @param {string} key - The stable key.
|
|
97
|
+
* @param {() => object|null} resolve - Finds the object at the key now.
|
|
98
|
+
* @returns {string} The id, the same for every call with the same kind and key.
|
|
99
|
+
*/
|
|
100
|
+
keyedId(kind, key, resolve) {
|
|
101
|
+
const full = `${kind}\0${key}`;
|
|
102
|
+
let id = this._keyIds.get(full);
|
|
103
|
+
if (!id) {
|
|
104
|
+
id = `${kind}:${this._next++}`;
|
|
105
|
+
this._keyIds.set(full, id);
|
|
106
|
+
}
|
|
107
|
+
this._resolvers.set(id, resolve);
|
|
108
|
+
return id;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* @param {string} id - An id given by {@link RefRegistry#idOf} or {@link RefRegistry#keyedId}.
|
|
113
|
+
* @returns {object|null} The object, or null when the id is unknown or its object is gone.
|
|
114
|
+
*/
|
|
115
|
+
get(id) {
|
|
116
|
+
const resolve = this._resolvers.get(id);
|
|
117
|
+
if (resolve) return resolve() ?? null;
|
|
118
|
+
const obj = this._objects.get(id)?.deref();
|
|
119
|
+
if (!obj) this._objects.delete(id);
|
|
120
|
+
return obj ?? null;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Drops the ids of objects that were collected.
|
|
125
|
+
*
|
|
126
|
+
* @private
|
|
127
|
+
*/
|
|
128
|
+
_sweep() {
|
|
129
|
+
for (const [id, ref] of this._objects) {
|
|
130
|
+
if (!ref.deref()) this._objects.delete(id);
|
|
131
|
+
}
|
|
132
|
+
this._sweepAt = Math.max(1024, this._objects.size * 2);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export { RefRegistry, kindOf };
|
|
@@ -11,6 +11,8 @@ import { attachmentsText, backlink, formatName, makeSection, passDisplayName, pu
|
|
|
11
11
|
/** @import { FrameSnapshot } from './frame-graph-view.js' */
|
|
12
12
|
/** @import { ListRow } from './list-view.js' */
|
|
13
13
|
/** @import { PropertySection } from './model.js' */
|
|
14
|
+
/** @import { SnapshotContent } from './snapshot-view.js' */
|
|
15
|
+
/** @import { SnapshotItem } from './treemap-view.js' */
|
|
14
16
|
|
|
15
17
|
// render target properties the model shows explicitly, or that are plumbing
|
|
16
18
|
const SKIP_TARGET = [
|
|
@@ -110,12 +112,84 @@ function renderTargetRows(device, frame) {
|
|
|
110
112
|
const cells = [{ text: name, cls: 'pci-cell-name' }];
|
|
111
113
|
if (rt === device.backBuffer) cells.push({ text: 'backbuffer', cls: 'pci-cell-tag pci-cell-tag-info' });
|
|
112
114
|
cells.push({ text: `${rt.width}×${rt.height} ${attachmentsText(rt, device)}${rt.samples > 1 ? ` ×${rt.samples}` : ''}`, cls: 'pci-cell-info' });
|
|
113
|
-
cells.push({ text: uses ? `${uses} pass${uses === 1 ? '' : 'es'}` : 'unused this frame', cls: 'pci-cell-info pci-cell-right' });
|
|
115
|
+
cells.push({ text: uses ? `${uses} pass${uses === 1 ? '' : 'es'}` : 'unused this frame', cls: 'pci-cell-info pci-cell-right', field: 'passes' });
|
|
114
116
|
|
|
115
117
|
return { key: keyOf(rt), item: rt, name, dim: uses === 0, title: targetTitle(rt, device), cells };
|
|
116
118
|
});
|
|
117
119
|
}
|
|
118
120
|
|
|
121
|
+
/**
|
|
122
|
+
* @param {number} format - A PIXELFORMAT_* constant.
|
|
123
|
+
* @returns {number} The bytes of one pixel, taken as 4 for a format the table gives none for.
|
|
124
|
+
*/
|
|
125
|
+
function pixelBytes(format) {
|
|
126
|
+
return pixelFormatInfo.get(format)?.size ?? 4;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* What the Render targets tab measures in a snapshot: the GPU memory of every target's
|
|
131
|
+
* attachments, a group per target. A texture attached to several targets, such as a depth buffer
|
|
132
|
+
* shared by passes or a target per mip level, is counted once, under the first. Buffers the device
|
|
133
|
+
* keeps for a target without a texture to measure, such as the multisampled buffers it resolves
|
|
134
|
+
* from, an internal depth buffer and the swap chain, are estimated from their dimensions.
|
|
135
|
+
*
|
|
136
|
+
* @param {GraphicsDevice} device - The device.
|
|
137
|
+
* @returns {SnapshotContent} The attachments measured.
|
|
138
|
+
*/
|
|
139
|
+
function renderTargetSnapshot(device) {
|
|
140
|
+
/** @type {SnapshotItem[]} */
|
|
141
|
+
const items = [];
|
|
142
|
+
const counted = new Set();
|
|
143
|
+
const names = new Map();
|
|
144
|
+
let shared = 0;
|
|
145
|
+
const estimateOf = (rt, group, part, bytes, info) => {
|
|
146
|
+
if (bytes > 0) items.push({ key: `${keyOf(rt)}:${part}`, target: new WeakRef(rt), group: [group], name: part, size: bytes, info: `estimated: ${info}` });
|
|
147
|
+
};
|
|
148
|
+
const attachment = (rt, group, part, tex) => {
|
|
149
|
+
if (!tex) return;
|
|
150
|
+
if (counted.has(tex)) {
|
|
151
|
+
shared++;
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
counted.add(tex);
|
|
155
|
+
items.push({ key: `texture${tex.id}`, target: new WeakRef(rt), group: [group], name: part, size: tex.gpuSize, info: textureLine(part, tex) });
|
|
156
|
+
};
|
|
157
|
+
for (const rt of collectRenderTargets(device)) {
|
|
158
|
+
let group = `${targetName(rt, device)} ${rt.width}×${rt.height}`;
|
|
159
|
+
// two targets alike in name and size are still drawn apart
|
|
160
|
+
const seen = (names.get(group) ?? 0) + 1;
|
|
161
|
+
names.set(group, seen);
|
|
162
|
+
if (seen > 1) group = `${group} (${seen})`;
|
|
163
|
+
|
|
164
|
+
const pixels = rt.width * rt.height;
|
|
165
|
+
const samples = Math.max(1, rt.samples ?? 1);
|
|
166
|
+
const estimate = (part, bytes, info) => estimateOf(rt, group, part, bytes, info);
|
|
167
|
+
const texture = (part, tex) => attachment(rt, group, part, tex);
|
|
168
|
+
|
|
169
|
+
if (rt === device.backBuffer) {
|
|
170
|
+
const bytes = pixels * pixelBytes(device.backBufferFormat);
|
|
171
|
+
estimate('color', bytes, `the swap chain, ${formatName(device.backBufferFormat)}`);
|
|
172
|
+
if (samples > 1) estimate('color multisampled', bytes * samples, `${samples} samples resolved into the swap chain`);
|
|
173
|
+
}
|
|
174
|
+
const count = rt.colorBufferCount ?? 0;
|
|
175
|
+
for (let i = 0; i < count; i++) {
|
|
176
|
+
const color = rt.getColorBuffer(i);
|
|
177
|
+
const part = count > 1 ? `color[${i}]` : 'color';
|
|
178
|
+
texture(part, color);
|
|
179
|
+
if (color && samples > 1) estimate(`${part} multisampled`, pixels * pixelBytes(color.format) * samples, `${samples} samples resolved into the texture`);
|
|
180
|
+
}
|
|
181
|
+
const depth = rt.depthBuffer;
|
|
182
|
+
if (depth) {
|
|
183
|
+
texture('depth', depth);
|
|
184
|
+
if (samples > 1 && (depth.samples ?? 1) <= 1) estimate('depth multisampled', pixels * pixelBytes(depth.format) * samples, `${samples} samples`);
|
|
185
|
+
} else if (rt.depth) {
|
|
186
|
+
estimate('depth', pixels * 4 * samples, `an internal depth${rt.stencil ? ' and stencil' : ''} buffer, 4 bytes a sample`);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const note = shared ? `${shared} attachment${shared === 1 ? ' shared with an earlier target is' : 's shared with earlier targets are'} counted there.` : '';
|
|
190
|
+
return { measure: 'GPU memory of the render target attachments; multisampled buffers, internal depth buffers and the swap chain are estimated', items, note };
|
|
191
|
+
}
|
|
192
|
+
|
|
119
193
|
/**
|
|
120
194
|
* Everything the property view shows for a render target: its setup, the passes that rendered
|
|
121
195
|
* into it this frame (linked), its attachments, and every other public property.
|
|
@@ -269,20 +343,23 @@ function previewSupport(texture, device) {
|
|
|
269
343
|
}
|
|
270
344
|
|
|
271
345
|
/**
|
|
272
|
-
* The r, g, b and a channels an uncompressed color format stores, read from its name
|
|
273
|
-
* 'r', RG16F 'rg', SRGB8
|
|
274
|
-
*
|
|
275
|
-
*
|
|
346
|
+
* The r, g, b and a channels an uncompressed color format stores, read from its name, where each
|
|
347
|
+
* run of channel letters is followed by its bit count: R8 stores 'r', RG16F 'rg', SRGB8, RG11B10F
|
|
348
|
+
* and RGB9E5 'rgb', BGRA8 and RGB10A2 'rgba'. Sampling a channel the format lacks returns a
|
|
349
|
+
* constant (0, or 1 for alpha), so a preview of it shows nothing. Empty when the name carries no
|
|
350
|
+
* channel letters with bit counts: depth, and compressed formats such as ATC_RGB or BC7_RGBA.
|
|
276
351
|
*
|
|
277
352
|
* @param {number} format - A PIXELFORMAT_* constant.
|
|
278
353
|
* @returns {string} The stored channels as lower-case letters from 'rgba', or ''.
|
|
279
354
|
*/
|
|
280
355
|
function formatChannels(format) {
|
|
281
|
-
|
|
282
|
-
|
|
356
|
+
let name = pixelFormatInfo.get(format)?.name ?? '';
|
|
357
|
+
// older engines name RG11B10F '111110F', without its channel letters
|
|
358
|
+
if (name === '111110F') name = 'RG11B10F';
|
|
359
|
+
const match = /^S?((?:[RGBA]+\d+)+)/.exec(name);
|
|
283
360
|
if (!match) return '';
|
|
284
|
-
const letters =
|
|
361
|
+
const letters = match[1].toLowerCase();
|
|
285
362
|
return [...'rgba'].filter(letter => letters.includes(letter)).join('');
|
|
286
363
|
}
|
|
287
364
|
|
|
288
|
-
export { buildRenderTargetModel, formatChannels, isDepthFormat, previewAttachments, previewSupport, renderTargetRows, storedBottomUp };
|
|
365
|
+
export { buildRenderTargetModel, formatChannels, isDepthFormat, previewAttachments, previewSupport, renderTargetRows, renderTargetSnapshot, storedBottomUp };
|
package/src/shader-view.js
CHANGED
|
@@ -12,6 +12,8 @@ import { makeSection, push, reflectRows } from './model.js';
|
|
|
12
12
|
/** @import { Described } from './describe.js' */
|
|
13
13
|
/** @import { ListRow } from './list-view.js' */
|
|
14
14
|
/** @import { PropertySection } from './model.js' */
|
|
15
|
+
/** @import { SnapshotContent } from './snapshot-view.js' */
|
|
16
|
+
/** @import { SnapshotItem } from './treemap-view.js' */
|
|
15
17
|
|
|
16
18
|
// shader properties the model shows explicitly, plus plumbing and the source strings themselves
|
|
17
19
|
const SKIP_SHADER = [
|
|
@@ -235,11 +237,40 @@ function shaderRows(device) {
|
|
|
235
237
|
cells.push({ text: languageName(shader), cls: 'pci-cell-tag pci-cell-tag-info' });
|
|
236
238
|
if (compute) cells.push({ text: 'compute', cls: 'pci-cell-tag pci-cell-tag-info' });
|
|
237
239
|
if (shader.failed) cells.push({ text: 'failed', cls: 'pci-cell-tag' });
|
|
238
|
-
cells.push({ text: `#${shader.id}`, cls: 'pci-cell-info pci-cell-right' });
|
|
240
|
+
cells.push({ text: `#${shader.id}`, cls: 'pci-cell-info pci-cell-right', field: 'id' });
|
|
239
241
|
return { key: `shader${shader.id}`, item: shader, name, dim: !shader.ready, title: `${shader.label}\n${stateName(shader)}`, cells };
|
|
240
242
|
});
|
|
241
243
|
}
|
|
242
244
|
|
|
245
|
+
/**
|
|
246
|
+
* What the Shaders tab measures in a snapshot: the length of every shader's source, as the
|
|
247
|
+
* preprocessor left it, in a group per family. The engine names the variants it generates after
|
|
248
|
+
* their generator, then their pass, such as 'standard-forward-proc', so the family is the name up
|
|
249
|
+
* to its first dash; and the treemap shows how many variants each family made, as well as their
|
|
250
|
+
* size.
|
|
251
|
+
*
|
|
252
|
+
* @param {GraphicsDevice} device - The device.
|
|
253
|
+
* @returns {SnapshotContent} The shaders measured.
|
|
254
|
+
*/
|
|
255
|
+
function shaderSnapshot(device) {
|
|
256
|
+
/** @type {SnapshotItem[]} */
|
|
257
|
+
const items = collectShaders(device).map((shader) => {
|
|
258
|
+
const definition = shader.definition;
|
|
259
|
+
const stages = [['vertex', definition.vshader], ['fragment', definition.fshader], ['compute', definition.cshader]]
|
|
260
|
+
.filter(([, source]) => typeof source === 'string' && source !== '');
|
|
261
|
+
const name = shader.name || '(unnamed)';
|
|
262
|
+
return {
|
|
263
|
+
key: `shader${shader.id}`,
|
|
264
|
+
target: new WeakRef(shader),
|
|
265
|
+
group: [name.split('-')[0] || name],
|
|
266
|
+
name: `${name} #${shader.id}`,
|
|
267
|
+
size: stages.reduce((sum, [, source]) => sum + source.length, 0),
|
|
268
|
+
info: `${languageName(shader)} · ${stateName(shader)} · ${stages.map(([stage, source]) => `${stage} ${sourceLines(source)}`).join(', ')}`
|
|
269
|
+
};
|
|
270
|
+
});
|
|
271
|
+
return { measure: 'Length of each shader\'s source, in characters', items };
|
|
272
|
+
}
|
|
273
|
+
|
|
243
274
|
/**
|
|
244
275
|
* Everything the property view shows for a shader: identity and state, every kept version of its
|
|
245
276
|
* sources, the bind group layouts it was processed against, its vertex attributes, and every
|
|
@@ -284,4 +315,4 @@ function buildShaderModel(shader) {
|
|
|
284
315
|
return sections;
|
|
285
316
|
}
|
|
286
317
|
|
|
287
|
-
export { buildShaderModel, collectShaders, formatBindGroup, formatUniformBuffer, shaderRows, stateName };
|
|
318
|
+
export { buildShaderModel, collectShaders, formatBindGroup, formatUniformBuffer, shaderRows, shaderSnapshot, stateName };
|