├── .eslintrc.js
├── .github
└── workflows
│ └── build-and-deploy.yml
├── .gitignore
├── .vscode
└── settings.json
├── LICENSE.md
├── README.md
├── build
├── lib
│ └── spawn.js
└── tools
│ ├── prep-for-deploy.js
│ └── serve.js
├── package-lock.json
├── package.json
├── rollup.config.js
├── src
├── capabilities-info.ts
└── webgpu-memory.ts
├── test
├── assert.js
├── index.html
├── index.js
├── mocha-support.js
├── mocha.css
├── mocha.js
├── puppeteer.js
├── src
│ └── js
│ │ └── example-inject.js
└── tests
│ ├── buffer-tests.js
│ ├── canvas-tests.js
│ ├── device-tests.js
│ ├── query-set-tests.js
│ └── texture-tests.js
├── tsconfig.json
└── webgpu-memory.png
/.eslintrc.js:
--------------------------------------------------------------------------------
1 | /* global module */
2 | /* global __dirname */
3 | module.exports = {
4 | env: {
5 | browser: true,
6 | },
7 | // REMOVE THIS!
8 | globals: {
9 | 'GPUBufferUsage': 'readonly',
10 | 'GPUTextureUsage': 'readonly',
11 | 'GPUMapMode': 'readonly',
12 | },
13 | parser: '@typescript-eslint/parser',
14 | parserOptions: {
15 | sourceType: 'module',
16 | ecmaVersion: 11,
17 | tsconfigRootDir: __dirname,
18 | project: ['./jsconfig.json'],
19 | extraFileExtensions: ['.html'],
20 | },
21 | plugins: [
22 | '@typescript-eslint',
23 | 'eslint-plugin-optional-comma-spacing',
24 | 'eslint-plugin-one-variable-per-var',
25 | 'eslint-plugin-require-trailing-comma',
26 | ],
27 | extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
28 | rules: {
29 | // 'no-alert': 2,
30 | 'no-array-constructor': 2,
31 | 'no-caller': 2,
32 | 'no-catch-shadow': 2,
33 | 'no-const-assign': 2,
34 | 'no-eval': 2,
35 | 'no-extend-native': 2,
36 | 'no-extra-bind': 2,
37 | 'no-implied-eval': 2,
38 | 'no-inner-declarations': 0,
39 | 'no-iterator': 2,
40 | 'no-label-var': 2,
41 | 'no-labels': 2,
42 | 'no-lone-blocks': 0,
43 | 'no-multi-str': 2,
44 | 'no-native-reassign': 2,
45 | 'no-new': 2,
46 | 'no-new-func': 2,
47 | 'no-new-object': 2,
48 | 'no-new-wrappers': 2,
49 | 'no-octal-escape': 2,
50 | 'no-process-exit': 2,
51 | 'no-proto': 2,
52 | 'no-return-assign': 2,
53 | 'no-script-url': 2,
54 | 'no-self-assign': 0,
55 | 'no-sequences': 2,
56 | 'no-shadow-restricted-names': 2,
57 | 'no-spaced-func': 2,
58 | 'no-trailing-spaces': 2,
59 | 'no-undef-init': 2,
60 | 'no-unused-expressions': 2,
61 | 'no-use-before-define': 0,
62 | 'no-unused-vars': ['error', { 'argsIgnorePattern': '^_' }],
63 | '@typescript-eslint/no-unused-vars': ['error', { 'argsIgnorePattern': '^_' }],
64 | 'no-var': 2,
65 | 'no-with': 2,
66 | 'prefer-const': 2,
67 | 'consistent-return': 2,
68 | 'curly': [2, 'all'],
69 | 'no-extra-parens': [2, 'functions'],
70 | 'eqeqeq': 2,
71 | 'new-cap': 2,
72 | 'new-parens': 2,
73 | 'semi-spacing': [2, {'before': false, 'after': true}],
74 | 'space-infix-ops': 2,
75 | 'space-unary-ops': [2, { 'words': true, 'nonwords': false }],
76 | 'yoda': [2, 'never'],
77 |
78 | 'brace-style': [2, '1tbs', { 'allowSingleLine': false }],
79 | 'camelcase': [0],
80 | 'comma-spacing': 0,
81 | 'comma-dangle': 0,
82 | 'comma-style': [2, 'last'],
83 | 'optional-comma-spacing/optional-comma-spacing': [2, {'after': true}],
84 | 'dot-notation': 0,
85 | 'eol-last': [0],
86 | 'global-strict': [0],
87 | 'key-spacing': [0],
88 | 'no-comma-dangle': [0],
89 | 'no-irregular-whitespace': 2,
90 | 'no-multi-spaces': [0],
91 | 'no-loop-func': 0,
92 | 'no-obj-calls': 2,
93 | 'no-redeclare': [0],
94 | 'no-shadow': [0],
95 | 'no-undef': [2],
96 | 'no-unreachable': 2,
97 | 'one-variable-per-var/one-variable-per-var': [2],
98 | 'quotes': [2, 'single'],
99 | 'require-atomic-updates': 0,
100 | 'require-trailing-comma/require-trailing-comma': [2],
101 | 'require-yield': 0,
102 | 'semi': [2, 'always'],
103 | 'strict': [2, 'global'],
104 | 'space-before-function-paren': [2, 'never'],
105 | 'keyword-spacing': [1, {'before': true, 'after': true, 'overrides': {}} ],
106 | },
107 | overrides: [
108 | {
109 | files: [
110 | 'fix.js',
111 | ],
112 | parserOptions: {
113 | sourceType: 'script',
114 | },
115 | },
116 | ],
117 | };
118 |
119 |
--------------------------------------------------------------------------------
/.github/workflows/build-and-deploy.yml:
--------------------------------------------------------------------------------
1 | name: Build and Deploy
2 | on:
3 | push:
4 | tags:
5 | - v*
6 | permissions:
7 | contents: write
8 | jobs:
9 | build-and-deploy:
10 | runs-on: ubuntu-latest
11 | environment: deploy
12 | steps:
13 | - name: Checkout 🛎️
14 | uses: actions/checkout@v3
15 |
16 | - name: Use Node.js 😂
17 | uses: actions/setup-node@v3
18 | with:
19 | node-version: 20
20 |
21 | - name: Install and Build 🔧
22 | run: |
23 | npm ci
24 | npm run build-ci
25 |
26 | - name: Deploy 🚀
27 | uses: JamesIves/github-pages-deploy-action@v4
28 | with:
29 | folder: .
30 |
31 | - name: Publish to NPM 📖
32 | uses: JS-DevTools/npm-publish@v2
33 | with:
34 | token: ${{ secrets.NPM_TOKEN }}
35 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # -- clip-for-deploy-start --
2 |
3 | /dist/1.x
4 |
5 | # -- clip-for-deploy-end --
6 |
7 | *.pyc
8 | .DS_Store
9 | node_modules
10 |
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "cSpell.words": [
3 | ]
4 | }
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2023 Gregg Tavares
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | this software and associated documentation files (the "Software"), to deal in
7 | the Software without restriction, including without limitation the rights to
8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 | the Software, and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # WebGPU-Memory
2 |
3 |
4 |
5 | This is a WebGPU-Memory tracker. You add the script to your page
6 | before you initialize WebGPU and then for a given context
7 | you can ask how much WebGPU memory you're using.
8 |
9 | Note: This is only a guess as various GPUs have different
10 | internal requirements. For example a GPU might
11 | have alignment requirements. Still, this is likely to give
12 | a reasonable approximation.
13 |
14 | **You can use this without manually adding to your page
15 | via the [webgpu-dev-extension](https://github.com/greggman/webgpu-dev-extension).**
16 |
17 | ## Usage
18 |
19 | ```html
20 |
21 |
34 |
35 |
71 |