Last active
March 28, 2024 21:00
-
-
Save greggman/9192f9a7ff5145853d4a9abfbc45d2ab to your computer and use it in GitHub Desktop.
WebGPU DevTools Custom Formatter (base vs derived)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*bug-in-github-api-content-can-not-be-empty*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://greggman.github.io./webgpu-utils/dist/1.x/webgpu-utils.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{"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