Skip to content

Instantly share code, notes, and snippets.

@greggman
Last active March 28, 2024 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greggman/9192f9a7ff5145853d4a9abfbc45d2ab to your computer and use it in GitHub Desktop.
Save greggman/9192f9a7ff5145853d4a9abfbc45d2ab to your computer and use it in GitHub Desktop.
WebGPU DevTools Custom Formatter (base vs derived)
/*bug-in-github-api-content-can-not-be-empty*/
<script src="https://greggman.github.io./webgpu-utils/dist/1.x/webgpu-utils.js"></script>
function getJsonML(object, innerTag) {
const { usage } = object;
const usageFlags = [];
for (const [k, v] of Object.entries(GPUBufferUsage)) {
if (usage & v) usageFlags.push(k);
}
const colorSubtle = 'color: var(--sys-color-token-subtle';
const colorAttributeValue = 'color: var(--sys-color-token-attribute-value';
const colorPropertySpecial = 'color: var(--sys-color-token-property-special';
function getValue(key, value) {
switch (key) {
case 'usage':
return [
'span',
['span', { style: colorAttributeValue }, `${usage}`],
' (',
['span', { style: colorPropertySpecial }, `${usageFlags.join("|")}`],
')',
];
default:
return ['object', {object: value}];
}
}
const props = [];
for (const key in object) {
const value = object[key];
if (typeof value !== 'function') {
props.push([
innerTag,
['span', { className: 'name' }, key],
': ',
getValue(key, value),
]);
}
}
return props;
}
const DevtoolsFormatter = {
header: (object) => {
if (!(object instanceof Base)) {
return null;
}
return [
'span',
['span', 'Base {',
[
'span',
['span', 'name'],
': ',
object.name,
],
],
'}',
];
},
hasBody: () => true,
body: () => null,
};
window.devtoolsFormatters = [DevtoolsFormatter];
class Base {
name = 'foo';
}
class Dervied extends Base {
age = 35;
}
const b = new Base();
const d = new Dervied();
console.log(b);
console.log(d);
{"name":"WebGPU DevTools Custom Formatter (base vs derived)","settings":{},"filenames":["index.html","index.css","index.js"]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment