@grepp/detect-gpu 5.0.70

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +117 -0
  3. package/package.json +103 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Tim van Scherpenzeel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, 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,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,117 @@
1
+ # Detect GPU
2
+
3
+ [![npm version](https://badge.fury.io/js/detect-gpu.svg)](https://badge.fury.io/js/detect-gpu)
4
+ [![gzip size](https://img.badgesize.io/https:/unpkg.com/detect-gpu/dist/detect-gpu.esm.js?compression=gzip)](https://unpkg.com/detect-gpu)
5
+ [![install size](https://packagephobia.now.sh/badge?p=detect-gpu)](https://packagephobia.now.sh/result?p=detect-gpu)
6
+
7
+ Classifies GPUs based on their 3D rendering benchmark score allowing the developer to provide sensible default settings for graphically intensive applications. Think of it like a user-agent detection for the GPU but more powerful.
8
+
9
+ ## Demo
10
+
11
+ [Live demo](https://pmndrs.github.io/detect-gpu/)
12
+
13
+ ## Installation
14
+
15
+ By default we use the [UNPKG](https://unpkg.com) CDN to host the benchmark data. If you would like to serve the benchmark data yourself download the required benchmarking data from [benchmarks.tar.gz](https://github.com/pmndrs/detect-gpu/raw/master/benchmarks.tar.gz) and serve it from a public directory.
16
+
17
+ Make sure you have [Node.js](http://nodejs.org/) installed.
18
+
19
+ ```sh
20
+ $ npm install detect-gpu
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ ```ts
26
+ import { getGPUTier } from 'detect-gpu';
27
+
28
+ (async () => {
29
+ const gpuTier = await getGPUTier();
30
+
31
+ // Example output:
32
+ // {
33
+ // "tier": 1,
34
+ // "isMobile": false,
35
+ // "type": "BENCHMARK",
36
+ // "fps": 21,
37
+ // "gpu": "intel iris graphics 6100"
38
+ // }
39
+ })();
40
+ ```
41
+
42
+ `detect-gpu` uses rendering benchmark scores (framerate, normalized by resolution) in order to determine what tier should be assigned to the user's GPU. If no `WebGLContext` can be created, the GPU is blocklisted or the GPU has reported to render on less than `15 fps` `tier: 0` is assigned. One should provide a fallback to a non-WebGL experience.
43
+
44
+ Based on the reported `fps` the GPU is then classified into either `tier: 1 (>= 15 fps)`, `tier: 2 (>= 30 fps)` or `tier: 3 (>= 60 fps)`. The higher the tier the more graphically intensive workload you can offer to the user.
45
+
46
+ ## API
47
+
48
+ ```ts
49
+ getGPUTier({
50
+ /**
51
+ * URL of directory where benchmark data is hosted.
52
+ *
53
+ * @default https://unpkg.com/detect-gpu@{version}/dist/benchmarks
54
+ */
55
+ benchmarksURL?: string;
56
+ /**
57
+ * Optionally pass in a WebGL context to avoid creating a temporary one
58
+ * internally.
59
+ */
60
+ glContext?: WebGLRenderingContext | WebGL2RenderingContext;
61
+ /**
62
+ * Whether to fail if the system performance is low or if no hardware GPU is
63
+ * available.
64
+ *
65
+ * @default false
66
+ */
67
+ failIfMajorPerformanceCaveat?: boolean;
68
+ /**
69
+ * Framerate per tier for mobile devices.
70
+ *
71
+ * @defaultValue [0, 15, 30, 60]
72
+ */
73
+ mobileTiers?: number[];
74
+ /**
75
+ * Framerate per tier for desktop devices.
76
+ *
77
+ * @defaultValue [0, 15, 30, 60]
78
+ */
79
+ desktopTiers?: number[];
80
+ /**
81
+ * Optionally override specific parameters. Used mainly for testing.
82
+ */
83
+ override?: {
84
+ renderer?: string;
85
+ /**
86
+ * Override whether device is an iPad.
87
+ */
88
+ isIpad?: boolean;
89
+ /**
90
+ * Override whether device is a mobile device.
91
+ */
92
+ isMobile?: boolean;
93
+ /**
94
+ * Override device screen size.
95
+ */
96
+ screenSize?: { width: number; height: number };
97
+ /**
98
+ * Override how benchmark data is loaded
99
+ */
100
+ loadBenchmarks?: (file: string) => Promise<ModelEntry[]>;
101
+ };
102
+ })
103
+ ```
104
+
105
+ ## Support
106
+
107
+ Special care has been taken to make sure all browsers that support `WebGL` are also supported by `detect-gpu` including `IE 11`.
108
+
109
+ ## Changelog
110
+
111
+ [Changelog](CHANGELOG.md)
112
+
113
+ ## Licence
114
+
115
+ My work is released under the [MIT license](https://raw.githubusercontent.com/pmndrs/detect-gpu/master/LICENSE).
116
+
117
+ `detect-gpu` uses both mobile and desktop benchmarking scores from [https://gfxbench.com](https://gfxbench.com).
package/package.json ADDED
@@ -0,0 +1,103 @@
1
+ {
2
+ "name": "@grepp/detect-gpu",
3
+ "version": "5.0.70",
4
+ "description": "Classify GPU's based on their benchmark score in order to provide an adaptive experience.",
5
+ "author": "Tim van Scherpenzeel",
6
+ "license": "MIT",
7
+ "main": "dist/detect-gpu.umd.js",
8
+ "module": "dist/detect-gpu.esm.js",
9
+ "types": "dist/src/index.d.ts",
10
+ "homepage": "https://github.com/pmndrs/detect-gpu#readme",
11
+ "bugs": {
12
+ "url": "https://github.com/pmndrs/detect-gpu/issues"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/grepp/detect-gpu.git"
17
+ },
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "keywords": [
22
+ "gpu",
23
+ "detect",
24
+ "webgl",
25
+ "webgl2",
26
+ "three.js",
27
+ "babylonjs",
28
+ "three",
29
+ "babylon",
30
+ "3d",
31
+ "typescript",
32
+ "javascript"
33
+ ],
34
+ "scripts": {
35
+ "start": "rollup -c rollup/config.lib.ts -w --configPlugin rollup-plugin-typescript2",
36
+ "lint": "eslint \"src/**/*.ts\" \"test/**/*.ts\" \"test/**/*.test.ts\" \"rollup/**/*.ts\" \"scripts/**/*.ts\" \"scripts/**/*.js\" --fix --cache --cache-location ~/.eslintcache/eslintcache",
37
+ "test": "jest --verbose=false",
38
+ "test:watch": "jest --watch",
39
+ "test:coverage": "jest --coverage",
40
+ "test:debug": "node --inspect-brk ./node_modules/jest/bin/jest --runInBand --no-cache --watch",
41
+ "prebuild": "rimraf dist",
42
+ "build": "rollup -c rollup/config.lib.ts --configPlugin rollup-plugin-typescript2",
43
+ "example": "rollup -w -c rollup/config.dev.ts --configPlugin rollup-plugin-typescript2",
44
+ "parse-analytics": "node ./scripts/analytics_parser.js",
45
+ "update-benchmarks": "rimraf benchmarks && mkdir -p benchmarks && mkdir -p benchmarks-min && ts-node -O '{\"module\":\"commonjs\"}' ./scripts/update_benchmarks.ts && tar -czvf benchmarks.tar.gz benchmarks-min/*.json && rm -rf benchmarks-min"
46
+ },
47
+ "dependencies": {
48
+ "webgl-constants": "^1.1.1"
49
+ },
50
+ "devDependencies": {
51
+ "@rollup/plugin-json": "^6.0.0",
52
+ "@rollup/plugin-node-resolve": "^15.1.0",
53
+ "@types/jest": "^29.5.3",
54
+ "@typescript-eslint/eslint-plugin": "^6.4.0",
55
+ "@typescript-eslint/parser": "^6.4.0",
56
+ "csvtojson": "^2.0.10",
57
+ "eslint": "^8.4.1",
58
+ "eslint-config-prettier": "^9.0.0",
59
+ "eslint-plugin-prettier": "^5.0.0",
60
+ "jest": "^29.6.2",
61
+ "jest-environment-jsdom": "^29.6.2",
62
+ "moment": "^2.29.1",
63
+ "prettier": "^3.0.1",
64
+ "puppeteer": "^24.13.0",
65
+ "rimraf": "^5.0.1",
66
+ "rollup": "^3.28.0",
67
+ "rollup-plugin-commonjs": "^10.1.0",
68
+ "rollup-plugin-copy": "^3.4.0",
69
+ "rollup-plugin-filesize": "^10.0.0",
70
+ "rollup-plugin-livereload": "^2.0.0",
71
+ "rollup-plugin-serve": "^2.0.2",
72
+ "rollup-plugin-sourcemaps": "^0.6.3",
73
+ "rollup-plugin-terser": "^7.0.2",
74
+ "rollup-plugin-typescript2": "^0.31.1",
75
+ "ts-jest": "^29.1.1",
76
+ "ts-node": "^10.0.0",
77
+ "typescript": "^5.1.6"
78
+ },
79
+ "jest": {
80
+ "testEnvironmentOptions": {
81
+ "url": "http://localhost"
82
+ },
83
+ "moduleFileExtensions": [
84
+ "js",
85
+ "ts"
86
+ ],
87
+ "testMatch": [
88
+ "**/test/**/*.test.ts"
89
+ ],
90
+ "testPathIgnorePatterns": [
91
+ "<rootDir>/test/data.ts"
92
+ ],
93
+ "preset": "ts-jest",
94
+ "transform": {
95
+ "^.+\\.tsx?$": [
96
+ "ts-jest",
97
+ {
98
+ "tsconfig": "tsconfig.json"
99
+ }
100
+ ]
101
+ }
102
+ }
103
+ }