// luma.gl // SPDX-License-Identifier: MIT // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors import type {PickingInfo} from '@deck.gl/core'; import {ArrowExamplePanelManager} from '../../proposals/shared/arrow/arrow-example-panels'; import {makeHtmlCustomPanel} from '../../proposals/shared/example-panels'; import type {GPUTraceCullingStats} from './gpu-trace-culling-effect'; import {getTraceRow, type makeDeckTraceData} from './trace-data'; type TraceData = ReturnType; /** Owns the explanatory panels and tooltip for the GPU-culled trace example. */ export class GPUCulledTraceUserInterface { readonly panelManager: ArrowExamplePanelManager; private readonly traceData: TraceData; private statsElement: HTMLElement | null = null; private cullingStats: GPUTraceCullingStats; constructor(traceData: TraceData, initialStats: GPUTraceCullingStats) { this.traceData = traceData; this.cullingStats = initialStats; this.panelManager = new ArrowExamplePanelManager({ descriptionHtml: '

One WebGPU command graph culls trace blocks and row-indexed Arrow glyph records before deck.gl draws both layers indirectly.

', settingsPanel: () => makeHtmlCustomPanel({ id: 'gpu-culled-trace-culling', title: 'Culling', html: '
', onRender: root => { this.statsElement = root.querySelector('[data-gpu-trace-culling-stats]'); renderCullingStats(this.statsElement, this.cullingStats); return () => { this.statsElement = null; }; } }) }); this.panelManager.setTableEntries([ {id: 'gpu-trace-text', label: 'Trace text', kind: 'source', table: traceData.textTable} ]); } mount(): void { this.panelManager.mount(); } finalize(): void { this.panelManager.finalize(); } updateCullingStats(stats: GPUTraceCullingStats): void { this.cullingStats = stats; renderCullingStats(this.statsElement, stats); } getTooltip(info: PickingInfo): {html: string} | null { const row = getTraceRow(this.traceData, info.index); if (!row) return null; return { html: `
${escapeHtml(row.name)}
group: ${row.group}
start: ${row.start.toFixed(3)}
duration: ${row.duration.toFixed(3)}
lane: ${row.lane}
` }; } } function renderCullingStats(element: HTMLElement | null, stats: GPUTraceCullingStats): void { if (!element) return; const glyphCounts = stats.totalGlyphs ? `${formatCount(stats.visibleGlyphs)} / ${formatCount(stats.totalGlyphs)}` : escapeHtml(stats.labelStatus); element.innerHTML = `
Visible blocks${formatCount(stats.visibleBlocks)} / ${formatCount(stats.totalBlocks)} Outside view${formatCount(stats.outsideBlocks)} Too small (<1 px)${formatCount(stats.smallBlocks)} Visible glyphs${glyphCounts} Graph nodes${stats.graphNodeCount} CPU graph encode${stats.encodeTimeMilliseconds.toFixed(2)} ms Logical scratch${formatBytes(stats.logicalTransientBytes)} Physical scratch${formatBytes(stats.physicalTransientBytes)} Transient reuse${stats.transientReusePercentage.toFixed(0)}%
`; } function escapeHtml(value: string): string { return value.replace(/[&<>"']/g, character => { const entities: Record = { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }; return entities[character]!; }); } function formatCount(value: number): string { return new Intl.NumberFormat('en-US', {notation: 'compact', maximumFractionDigits: 1}).format( value ); } function formatBytes(value: number): string { if (value < 1024) return `${value} B`; if (value < 1024 * 1024) return `${(value / 1024).toFixed(1)} KiB`; return `${(value / 1024 / 1024).toFixed(1)} MiB`; }