Files
gods-eye-view/src/render/cesium/uploadProbe.js
T
Sameh Khamis 347427f83d Draw transit vehicles through the renderer ports, off the Cesium list
Transit drew its vehicles into two Cesium billboard collections and culled,
turned and floored them through the Cesium scene. It now draws them as two
draw-port icon sets, still and moving, registered with the sprite order by
set id in the same places. Each marker is a plain record; a frame writes the
changed ones in one upsert per set, and markers taken out in one task go in
one removal. Clicks read the draw-port hit.

Visibility uses the query port's horizon test and the frustum planes of the
camera port's pose. Icons stay turned in screen space by an exact projection
through the query port, the same answer the Cesium helper gave. The flat
globe is told from terrain by asking the height service once per surface
change; floors are read again when the answer flips. The mesh floor sampler
sees through the layer's sets by id. The camera pose and surface version are
read once per task.

The Cesium draw port now moves and turns an icon without restyling it. The
GL upload probe moves to src/render/cesium/uploadProbe.js, which the QA
scripts hand to the frame probe; the QA scripts read the billboards drawn for
each set.
2026-11-08 21:44:22 -08:00

92 lines
3.0 KiB
JavaScript

/**
* @module render/cesium/uploadProbe
* @description A QA probe: the bytes the WebGL context is handed
* (`bufferData`, `bufferSubData`) while the hosts of some draw sets update,
* frame by frame. A layer's frame probe takes it as its `uploads` (the
* transit layer's `_measureTransitFramesForTest`), so the layer itself
* stays off the default renderer. Diagnostics only: it wraps the context's
* methods and the hosts' `update` until `stop()`.
*/
import { webglContext } from './internals.js';
/**
* Count the bytes uploaded while the hosts of `setIds` update. Hosts are
* found by the `drawSetId` the draw port names them with, again at each
* `reset()`, so a host a rebuild puts in a set's place is counted too.
* @param {object} viewer A Cesium viewer.
* @param {readonly string[]} setIds
* @returns {{reset: () => void, bytes: () => number, stop: () => void}}
*/
export function countDrawSetUploads(viewer, setIds) {
const scene = viewer.scene;
const ids = new Set(setIds);
const gl = webglContext(scene);
let active = false;
let upload = 0;
const restores = [];
if (gl) {
for (const name of ['bufferData', 'bufferSubData']) {
const original = gl[name];
gl[name] = function (...args) {
if (active) {
const value = args[name === 'bufferData' ? 1 : 2];
const offset = args[3] || 0;
const length = args[4];
upload +=
typeof value === 'number'
? value
: value
? length !== undefined
? length * (value.BYTES_PER_ELEMENT || 1)
: value.byteLength - offset * (value.BYTES_PER_ELEMENT || 1)
: 0;
}
return original.apply(this, args);
};
restores.push(() => {
gl[name] = original;
});
}
}
// Hosts wrapped so far, and how to give each its own `update` back (an
// inherited one by deleting the wrapper).
const wrapped = new Map();
function wrapHosts() {
const primitives = scene.primitives;
for (let i = 0; i < (primitives?.length ?? 0); i++) {
const host = primitives.get(i);
if (!ids.has(host?.drawSetId) || wrapped.has(host)) continue;
const original = host.update;
const own = Object.prototype.hasOwnProperty.call(host, 'update');
host.update = function (frameState) {
active = true;
try {
return original.call(this, frameState);
} finally {
active = false;
}
};
wrapped.set(host, { original, own, wrapper: host.update });
}
}
wrapHosts();
return {
reset() {
upload = 0;
wrapHosts();
},
bytes: () => upload,
stop() {
for (const restore of restores) restore();
restores.length = 0;
for (const [host, { original, own, wrapper }] of wrapped) {
// A host whose update was replaced meanwhile keeps the new one.
if (host.update !== wrapper) continue;
if (own) host.update = original;
else delete host.update;
}
wrapped.clear();
},
};
}