@playcanvas/inspector 0.5.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 +53 -4
- package/package.json +2 -2
- package/src/asset-view.js +65 -2
- package/src/camera-view.js +1 -1
- package/src/describe.js +1 -1
- package/src/inspector.js +368 -48
- package/src/layer-view.js +235 -0
- package/src/mcp-tools.js +6 -3
- package/src/memory-view.js +59 -3
- package/src/mesh-view.js +50 -1
- package/src/ref-registry.js +2 -1
- package/src/render-target-view.js +75 -1
- package/src/shader-view.js +32 -1
- package/src/snapshot-view.js +268 -0
- package/src/styles.js +261 -0
- package/src/texture-view.js +1 -1
- package/src/treemap-view.js +837 -0
- package/types/asset-view.d.ts +10 -0
- package/types/inspector.d.ts +147 -2
- package/types/layer-view.d.ts +80 -0
- package/types/memory-view.d.ts +11 -0
- package/types/mesh-view.d.ts +13 -0
- package/types/render-target-view.d.ts +12 -0
- 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
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SORTMODE_BACK2FRONT, SORTMODE_CUSTOM, SORTMODE_FRONT2BACK, SORTMODE_MANUAL, SORTMODE_MATERIALMESH, SORTMODE_NONE
|
|
3
|
+
} from 'playcanvas';
|
|
4
|
+
|
|
5
|
+
import { describeValue } from './describe.js';
|
|
6
|
+
import { nodeLabel } from './memory-view.js';
|
|
7
|
+
import { makeSection, push, read } from './model.js';
|
|
8
|
+
|
|
9
|
+
/** @import { AppBase, Layer, LayerComposition } from 'playcanvas' */
|
|
10
|
+
/** @import { ListRow } from './list-view.js' */
|
|
11
|
+
/** @import { PropertySection } from './model.js' */
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* What the Layers tab offers on a layer, supplied by the inspector.
|
|
15
|
+
*
|
|
16
|
+
* @typedef {object} LayerActions
|
|
17
|
+
* @property {(layer: Layer, hidden: boolean) => void} hide - Hides the layer from the view, or shows
|
|
18
|
+
* it again.
|
|
19
|
+
* @property {(layer: Layer) => boolean} hidden - Whether the inspector hides the layer.
|
|
20
|
+
* @ignore
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
const SORT_MODES = new Map([
|
|
24
|
+
[SORTMODE_NONE, 'none'],
|
|
25
|
+
[SORTMODE_MANUAL, 'manual (draw order)'],
|
|
26
|
+
[SORTMODE_MATERIALMESH, 'material, mesh'],
|
|
27
|
+
[SORTMODE_BACK2FRONT, 'back to front'],
|
|
28
|
+
[SORTMODE_FRONT2BACK, 'front to back'],
|
|
29
|
+
[SORTMODE_CUSTOM, 'custom']
|
|
30
|
+
]);
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @param {number} mode - A sort mode.
|
|
34
|
+
* @returns {string} Its name.
|
|
35
|
+
*/
|
|
36
|
+
function sortModeName(mode) {
|
|
37
|
+
return SORT_MODES.get(mode) ?? String(mode);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* One entry of the composition: a layer's opaque or transparent half, which the composition orders
|
|
42
|
+
* on its own, so a layer's halves can render far apart.
|
|
43
|
+
*
|
|
44
|
+
* @typedef {object} SubLayer
|
|
45
|
+
* @property {Layer} layer - The layer.
|
|
46
|
+
* @property {boolean} transparent - Whether it is the transparent half.
|
|
47
|
+
* @property {boolean} enabled - Whether the composition renders it: the layer and the half enabled.
|
|
48
|
+
* @property {number} index - Its place in the composition.
|
|
49
|
+
* @ignore
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The entries of the composition, in the order it renders them.
|
|
54
|
+
*
|
|
55
|
+
* @param {LayerComposition|null|undefined} composition - The scene's composition.
|
|
56
|
+
* @returns {SubLayer[]} The entries.
|
|
57
|
+
*/
|
|
58
|
+
function collectSubLayers(composition) {
|
|
59
|
+
if (!composition) return [];
|
|
60
|
+
return composition.layerList.map((layer, index) => {
|
|
61
|
+
const transparent = !!composition.subLayerList[index];
|
|
62
|
+
return { layer, transparent, enabled: layer.enabled && !!composition.subLayerEnabled[index], index };
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @param {Layer} layer - A layer.
|
|
68
|
+
* @param {boolean} transparent - Whether to count the transparent half.
|
|
69
|
+
* @returns {number} How many of its mesh instances that half draws.
|
|
70
|
+
*/
|
|
71
|
+
function instanceCount(layer, transparent) {
|
|
72
|
+
let count = 0;
|
|
73
|
+
for (const instance of layer.meshInstances) {
|
|
74
|
+
if (!!instance.transparent === transparent) count++;
|
|
75
|
+
}
|
|
76
|
+
return count;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The mesh instances of a half of a layer the last frame drew for a camera, after culling, as the
|
|
81
|
+
* renderer left them. Read without {@link Layer#getCulledInstances}, which would add an entry for a
|
|
82
|
+
* camera that never rendered the layer.
|
|
83
|
+
*
|
|
84
|
+
* @param {Layer} layer - A layer.
|
|
85
|
+
* @param {import('playcanvas').CameraComponent} camera - A camera rendering it. The layer keeps its
|
|
86
|
+
* culled instances by the component's engine camera.
|
|
87
|
+
* @param {boolean} transparent - Which half.
|
|
88
|
+
* @returns {number|null} The count, or null when the layer kept none for the camera.
|
|
89
|
+
*/
|
|
90
|
+
function visibleCount(layer, camera, transparent) {
|
|
91
|
+
const culled = /** @type {any} */ (layer)._visibleInstances?.get(camera.camera);
|
|
92
|
+
if (!culled) return null;
|
|
93
|
+
return (transparent ? culled.transparent : culled.opaque)?.length ?? 0;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @param {Layer} layer - A layer.
|
|
98
|
+
* @returns {import('playcanvas').Light[]} The lights lighting it.
|
|
99
|
+
*/
|
|
100
|
+
function layerLights(layer) {
|
|
101
|
+
return /** @type {any} */ (layer)._lights ?? [];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Makes labels unique within a section, as the rows of a section are keyed by their label, and two
|
|
106
|
+
* cameras or lights can share a name.
|
|
107
|
+
*
|
|
108
|
+
* @returns {(label: string) => string} Gives a label, numbered from its second use.
|
|
109
|
+
*/
|
|
110
|
+
function uniqueLabels() {
|
|
111
|
+
const used = new Map();
|
|
112
|
+
return (label) => {
|
|
113
|
+
const n = (used.get(label) ?? 0) + 1;
|
|
114
|
+
used.set(label, n);
|
|
115
|
+
return n === 1 ? label : `${label} (${n})`;
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* One row per entry of the composition, in render order, dimmed when it does not render.
|
|
121
|
+
*
|
|
122
|
+
* @param {AppBase} app - The app.
|
|
123
|
+
* @param {(layer: Layer) => boolean} [hidden] - Whether the inspector hides a layer.
|
|
124
|
+
* @returns {ListRow[]} The rows.
|
|
125
|
+
*/
|
|
126
|
+
function layerRows(app, hidden = () => false) {
|
|
127
|
+
return collectSubLayers(app.scene?.layers).map(({ layer, transparent, enabled, index }) => {
|
|
128
|
+
const half = transparent ? 'transparent' : 'opaque';
|
|
129
|
+
const cells = [
|
|
130
|
+
{ text: String(index), cls: 'pci-cell-index' },
|
|
131
|
+
{ text: layer.name, cls: 'pci-cell-name' },
|
|
132
|
+
{ text: half, cls: `pci-cell-tag${transparent ? '' : ' pci-cell-tag-info'}` }
|
|
133
|
+
];
|
|
134
|
+
if (hidden(layer)) cells.push({ text: 'hidden', cls: 'pci-cell-tag' });
|
|
135
|
+
else if (!layer.enabled) cells.push({ text: 'off', cls: 'pci-cell-tag' });
|
|
136
|
+
else if (!enabled) cells.push({ text: `${half} off`, cls: 'pci-cell-tag' });
|
|
137
|
+
const cameras = layer.cameras.length;
|
|
138
|
+
const instances = instanceCount(layer, transparent);
|
|
139
|
+
const splats = /** @type {any} */ (layer).gsplatPlacements?.length ?? 0;
|
|
140
|
+
const info = [`id ${layer.id}`, `${instances} instances`];
|
|
141
|
+
if (splats) info.push(`${splats} splats`);
|
|
142
|
+
info.push(`${cameras} ${cameras === 1 ? 'camera' : 'cameras'}`);
|
|
143
|
+
cells.push({ text: info.join(' · '), cls: 'pci-cell-info' });
|
|
144
|
+
return {
|
|
145
|
+
key: `layer${layer.id}${transparent ? 't' : 'o'}`,
|
|
146
|
+
item: layer,
|
|
147
|
+
name: layer.name,
|
|
148
|
+
// drawing nothing for no camera, the entry costs nothing and shows nothing
|
|
149
|
+
dim: !enabled || cameras === 0,
|
|
150
|
+
title: `${layer.name} (id ${layer.id}), ${half}, ${index} in the composition`,
|
|
151
|
+
cells
|
|
152
|
+
};
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Everything the property view shows for a layer: where its halves render in the composition, how
|
|
158
|
+
* each sorts, the cameras rendering it with what each drew of it last frame, its lights and its mesh
|
|
159
|
+
* instances, and a way to hide it from the view.
|
|
160
|
+
*
|
|
161
|
+
* @param {Layer} layer - The layer.
|
|
162
|
+
* @param {{ app: AppBase, layerActions: LayerActions }} ctx - The app, and what the tab offers.
|
|
163
|
+
* @returns {PropertySection[]} The sections.
|
|
164
|
+
*/
|
|
165
|
+
function buildLayerModel(layer, ctx) {
|
|
166
|
+
const composition = ctx.app.scene?.layers ?? null;
|
|
167
|
+
const halves = collectSubLayers(composition).filter(sub => sub.layer === layer);
|
|
168
|
+
const hidden = ctx.layerActions.hidden(layer);
|
|
169
|
+
|
|
170
|
+
const general = makeSection('layer', `Layer "${layer.name}"`);
|
|
171
|
+
push(general, 'id', read(layer, 'id'));
|
|
172
|
+
push(general, 'enabled', { text: String(layer.enabled), cls: 'bool' });
|
|
173
|
+
push(general, 'view', {
|
|
174
|
+
text: hidden ? 'hidden by the inspector' : (layer.enabled ? 'drawn' : 'off in the app'),
|
|
175
|
+
cls: 'obj',
|
|
176
|
+
actions: [{
|
|
177
|
+
text: hidden ? 'Show' : 'Hide',
|
|
178
|
+
title: hidden ? 'Draw the layer again, as the app had it' :
|
|
179
|
+
'Turn the layer off to see what the view is without it. Reset or closing the panel turns it back on',
|
|
180
|
+
disabled: !hidden && !layer.enabled,
|
|
181
|
+
run: () => ctx.layerActions.hide(layer, !hidden)
|
|
182
|
+
}]
|
|
183
|
+
});
|
|
184
|
+
for (const { transparent, enabled, index } of halves) {
|
|
185
|
+
push(general, transparent ? 'transparent' : 'opaque', {
|
|
186
|
+
text: `${index} in the composition${enabled ? '' : ', off'}`,
|
|
187
|
+
cls: 'obj'
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
if (halves.length === 0) push(general, 'composition', { text: 'not in the composition', cls: 'err' });
|
|
191
|
+
push(general, 'opaque sort', { text: sortModeName(layer.opaqueSortMode), cls: 'obj' });
|
|
192
|
+
push(general, 'transparent sort', { text: sortModeName(layer.transparentSortMode), cls: 'obj' });
|
|
193
|
+
push(general, 'clear', {
|
|
194
|
+
text: [layer.clearColorBuffer && 'color', layer.clearDepthBuffer && 'depth', layer.clearStencilBuffer && 'stencil'].filter(Boolean).join(', ') || 'nothing',
|
|
195
|
+
cls: 'obj'
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
const cameras = makeSection('cameras', `Cameras (${layer.cameras.length})`);
|
|
199
|
+
const cameraLabel = uniqueLabels();
|
|
200
|
+
for (const camera of layer.cameras) {
|
|
201
|
+
const entity = camera.entity;
|
|
202
|
+
const drawn = halves.map(({ transparent }) => {
|
|
203
|
+
const count = visibleCount(layer, camera, transparent);
|
|
204
|
+
return count === null ? null : `${count} ${transparent ? 'transparent' : 'opaque'}`;
|
|
205
|
+
}).filter(Boolean);
|
|
206
|
+
push(cameras, cameraLabel(entity ? nodeLabel(entity) : 'camera'), {
|
|
207
|
+
text: drawn.length ? `drew ${drawn.join(', ')}` : 'drew nothing yet',
|
|
208
|
+
cls: 'obj',
|
|
209
|
+
target: entity ?? undefined
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
if (layer.cameras.length === 0) push(cameras, 'none', { text: 'no camera renders this layer', cls: 'null' });
|
|
213
|
+
|
|
214
|
+
const lights = layerLights(layer);
|
|
215
|
+
const lightSection = makeSection('lights', `Lights (${lights.length})`);
|
|
216
|
+
const lightLabel = uniqueLabels();
|
|
217
|
+
for (const light of lights) {
|
|
218
|
+
const node = /** @type {any} */ (light)._node;
|
|
219
|
+
push(lightSection, lightLabel(node ? nodeLabel(node) : 'light'), {
|
|
220
|
+
text: `${['directional', 'omni', 'spot'][light.type] ?? light.type}${light.enabled ? '' : ', off'}${light.castShadows ? ', shadows' : ''}`,
|
|
221
|
+
cls: 'obj',
|
|
222
|
+
target: node ?? undefined
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const content = makeSection('content', 'Content');
|
|
227
|
+
push(content, 'mesh instances', describeValue(layer.meshInstances));
|
|
228
|
+
push(content, 'shadow casters', { text: String(layer.shadowCasters.length), cls: 'num' });
|
|
229
|
+
const splats = /** @type {any} */ (layer).gsplatPlacements;
|
|
230
|
+
if (splats?.length) push(content, 'splat placements', { text: String(splats.length), cls: 'num' });
|
|
231
|
+
|
|
232
|
+
return [general, cameras, lightSection, content];
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export { buildLayerModel, collectSubLayers, layerRows };
|
package/src/mcp-tools.js
CHANGED
|
@@ -2,6 +2,7 @@ import { Material, RenderTarget, Texture, revision, version } from 'playcanvas';
|
|
|
2
2
|
|
|
3
3
|
import { assetRows } from './asset-view.js';
|
|
4
4
|
import { cameraRows } from './camera-view.js';
|
|
5
|
+
import { layerRows } from './layer-view.js';
|
|
5
6
|
import { copyListRow, copySubject } from './copy-json.js';
|
|
6
7
|
import { passRows } from './frame-graph-view.js';
|
|
7
8
|
import { matchesFilter } from './hierarchy-view.js';
|
|
@@ -118,7 +119,7 @@ const MAX_LIMIT = 500;
|
|
|
118
119
|
const MAX_DEPTH = 4;
|
|
119
120
|
|
|
120
121
|
// the lists an index holds, and the most entries of each, so even a huge app gives a bounded index
|
|
121
|
-
const INDEX_LISTS = ['cameras', 'materials', 'textures', 'shaders', 'meshes', 'renderTargets', 'scripts', 'assets', 'passes'];
|
|
122
|
+
const INDEX_LISTS = ['cameras', 'layers', 'materials', 'textures', 'shaders', 'meshes', 'renderTargets', 'scripts', 'assets', 'passes'];
|
|
122
123
|
const MAX_INDEX_ENTRIES = 2000;
|
|
123
124
|
|
|
124
125
|
// how many objects a get copies in full, so a deep get of a big scene stays a sensible size
|
|
@@ -136,6 +137,7 @@ const LISTS = {
|
|
|
136
137
|
meshes: ({ app }) => meshListRows(surveyMeshes(app)),
|
|
137
138
|
scripts: ({ app }) => scriptListRows(surveyScripts(app)),
|
|
138
139
|
cameras: ({ app }) => cameraRows(app, null),
|
|
140
|
+
layers: ({ app }) => layerRows(app),
|
|
139
141
|
assets: ({ app }) => assetRows(app.assets, 'type'),
|
|
140
142
|
renderTargets: host => renderTargetRows(host.app.graphicsDevice, host.frame()),
|
|
141
143
|
passes: host => passRows(host.frame(), host.app.graphicsDevice),
|
|
@@ -960,7 +962,8 @@ const TOOLS = [{
|
|
|
960
962
|
}, {
|
|
961
963
|
name: 'playcanvas_list',
|
|
962
964
|
description: 'List what one tab of the inspector lists: textures, shaders, materials, meshes, scripts, ' +
|
|
963
|
-
'cameras, assets, renderTargets, passes (the frame graph
|
|
965
|
+
'cameras, layers (the layer composition in render order), assets, renderTargets, passes (the frame graph ' +
|
|
966
|
+
'of the last frame) or memory (GPU buffers ' +
|
|
964
967
|
'and textures by kind). Each entry has an id to pass to playcanvas_get, and the figures the list shows.',
|
|
965
968
|
inputSchema: {
|
|
966
969
|
type: 'object',
|
|
@@ -977,7 +980,7 @@ const TOOLS = [{
|
|
|
977
980
|
}, {
|
|
978
981
|
name: 'playcanvas_get',
|
|
979
982
|
description: 'Get an object by id, as the inspector shows it: an entity with its components, a mesh ' +
|
|
980
|
-
'instance, material, shader, texture, mesh, render target, pass, asset, script or buffer. Every object ' +
|
|
983
|
+
'instance, material, shader, texture, mesh, render target, pass, layer, asset, script or buffer. Every object ' +
|
|
981
984
|
'it links to carries an $id to get next, so links can be followed, such as entity -> render component ' +
|
|
982
985
|
'-> mesh instance -> material -> shader. Lists of what uses the object, and a node\'s parent, are ' +
|
|
983
986
|
'included as references. depth follows links in place, up to 4 away: 0 returns the object alone. ' +
|
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
|
|
@@ -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.
|
|
@@ -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/ref-registry.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Asset, Component, FramePass, GraphNode, Material, Mesh, MeshInstance, RenderTarget, Shader, Texture } from 'playcanvas';
|
|
1
|
+
import { Asset, Component, FramePass, GraphNode, Layer, Material, Mesh, MeshInstance, RenderTarget, Shader, Texture } from 'playcanvas';
|
|
2
2
|
|
|
3
3
|
import { LayerStepSelection } from './frame-graph-view.js';
|
|
4
4
|
import { isScriptClass } from './script-view.js';
|
|
@@ -19,6 +19,7 @@ function kindOf(obj) {
|
|
|
19
19
|
if (obj instanceof FramePass) return 'pass';
|
|
20
20
|
if (obj instanceof LayerStepSelection) return 'step';
|
|
21
21
|
if (obj instanceof Asset) return 'asset';
|
|
22
|
+
if (obj instanceof Layer) return 'layer';
|
|
22
23
|
if (isScriptClass(obj)) return 'script';
|
|
23
24
|
return 'object';
|
|
24
25
|
}
|
|
@@ -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 = [
|
|
@@ -116,6 +118,78 @@ function renderTargetRows(device, frame) {
|
|
|
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.
|
|
@@ -288,4 +362,4 @@ function formatChannels(format) {
|
|
|
288
362
|
return [...'rgba'].filter(letter => letters.includes(letter)).join('');
|
|
289
363
|
}
|
|
290
364
|
|
|
291
|
-
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 = [
|
|
@@ -240,6 +242,35 @@ function shaderRows(device) {
|
|
|
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 };
|