-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Neko Ayaka <neko@ayaka.moe>
- Loading branch information
1 parent
4e1870d
commit 8344c0d
Showing
7 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,7 @@ words: | |
- gcornut | ||
- giteeai | ||
- gltf | ||
- gpuu | ||
- grammyjs | ||
- groq | ||
- guiiai | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
{ | ||
"name": "@proj-airi/gpuu", | ||
"type": "module", | ||
"private": true, | ||
"description": "A collection of utilities for working with GPUs, especially for WebGPU.", | ||
"author": { | ||
"name": "Neko Ayaka", | ||
"email": "neko@ayaka.moe", | ||
"url": "https://github.com/nekomeowww" | ||
}, | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/moeru-ai/airi.git", | ||
"directory": "packages/gpuu" | ||
}, | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"import": "./dist/index.mjs", | ||
"require": "./dist/index.cjs" | ||
}, | ||
"./webgpu": { | ||
"types": "./dist/webgpu/index.d.ts", | ||
"import": "./dist/webgpu/index.mjs", | ||
"require": "./dist/webgpu/index.cjs" | ||
} | ||
}, | ||
"main": "./dist/index.cjs", | ||
"module": "./dist/index.mjs", | ||
"types": "./dist/index.d.ts", | ||
"files": [ | ||
"README.md", | ||
"dist", | ||
"package.json" | ||
], | ||
"scripts": { | ||
"dev": "pnpm run stub", | ||
"stub": "unbuild --stub", | ||
"build": "unbuild", | ||
"typecheck": "tsc --noEmit" | ||
}, | ||
"dependencies": { | ||
"defu": "^6.1.4" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^22.13.8", | ||
"@webgpu/types": "^0.1.54" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.warn('Please import \'@proj-airi/gpuu\' instead.') |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
export interface WebGPUCheckResult { | ||
supported: boolean | ||
fp16Supported: boolean | ||
isNode: boolean | ||
reason: string | ||
adapter?: GPUAdapter | ||
} | ||
|
||
export async function check(): Promise<WebGPUCheckResult> { | ||
try { | ||
if (isInNodejsRuntime()) | ||
return { supported: false, isNode: true, reason: '', fp16Supported: false } | ||
|
||
if (typeof navigator === 'undefined' || !navigator.gpu) | ||
return { supported: false, isNode: false, reason: 'WebGPU is not available (navigator.gpu is undefined)', fp16Supported: false } | ||
|
||
const adapter = await navigator.gpu.requestAdapter() | ||
if (!adapter) | ||
return { supported: false, isNode: false, reason: 'WebGPU is not supported (no adapter found)', fp16Supported: false } | ||
|
||
return { supported: true, isNode: false, reason: '', adapter, fp16Supported: adapter.features.has('shader-f16') } | ||
} | ||
catch (error) { | ||
const errorMessage = error instanceof Error ? error.toString() : String(error) | ||
return { supported: false, isNode: false, reason: errorMessage, fp16Supported: false } | ||
} | ||
} | ||
|
||
function isInNodejsRuntime() { | ||
// eslint-disable-next-line node/prefer-global/process | ||
return typeof process !== 'undefined' | ||
// eslint-disable-next-line node/prefer-global/process | ||
&& 'versions' in process && process.versions != null && typeof process.versions === 'object' | ||
// eslint-disable-next-line node/prefer-global/process | ||
&& 'node' in process.versions && process.versions.node != null | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { check } from './checker' | ||
export type { WebGPUCheckResult } from './checker' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"lib": [ | ||
"ESNext", | ||
"DOM", | ||
"DOM.Iterable", | ||
"WebWorker" | ||
], | ||
"module": "ESNext", | ||
"moduleResolution": "bundler", | ||
"types": [ | ||
"node", | ||
// @webgpu/types | ||
// https://www.npmjs.com/package/@webgpu/types | ||
"@webgpu/types" | ||
], | ||
"esModuleInterop": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"isolatedModules": true, | ||
"verbatimModuleSyntax": true, | ||
"skipLibCheck": true | ||
}, | ||
"include": [ | ||
"src/**/*.ts", | ||
"src/**/*.d.ts", | ||
"src/**/*.mts" | ||
] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.