Spaces:
Running
Running
updated `wgpu-devices.js`
Browse files- index.js +1 -17
- wgpu-devices.js +17 -0
index.js
CHANGED
@@ -5,27 +5,11 @@ import { CANVAS, CTX, COLORS, RENDER_PASS_DESCRIPTOR } from './wgpu-constants.js
|
|
5 |
import { createPipeline } from './wgpu-pipeline.js';
|
6 |
import { createState } from './wgpu-state.js';
|
7 |
import { generateGlyphVerticesForText } from './wgpu-text.js';
|
|
|
8 |
|
9 |
const canvas = document.querySelector('canvas');
|
10 |
const state = createState(config);
|
11 |
|
12 |
-
async function initializeWebGPU(navigator, adapter, canvas) {
|
13 |
-
const context = canvas.getContext('webgpu');
|
14 |
-
const device = await adapter?.requestDevice();
|
15 |
-
if (!device) {
|
16 |
-
alert('need a browser that supports WebGPU');
|
17 |
-
return { device: null, context: null, presentationFormat: null };
|
18 |
-
}
|
19 |
-
|
20 |
-
const presentationFormat = navigator.gpu.getPreferredCanvasFormat();
|
21 |
-
context.configure({
|
22 |
-
device,
|
23 |
-
format: presentationFormat,
|
24 |
-
});
|
25 |
-
|
26 |
-
return { device, context, presentationFormat };
|
27 |
-
}
|
28 |
-
|
29 |
async function main() {
|
30 |
const adapter = await navigator.gpu?.requestAdapter();
|
31 |
const { device, context, presentationFormat } = await initializeWebGPU(navigator, adapter, canvas);
|
|
|
5 |
import { createPipeline } from './wgpu-pipeline.js';
|
6 |
import { createState } from './wgpu-state.js';
|
7 |
import { generateGlyphVerticesForText } from './wgpu-text.js';
|
8 |
+
import { initializeWebGPU } from './wgpu-devices.js';
|
9 |
|
10 |
const canvas = document.querySelector('canvas');
|
11 |
const state = createState(config);
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
async function main() {
|
14 |
const adapter = await navigator.gpu?.requestAdapter();
|
15 |
const { device, context, presentationFormat } = await initializeWebGPU(navigator, adapter, canvas);
|
wgpu-devices.js
CHANGED
@@ -1 +1,18 @@
|
|
1 |
// wgpu-devices.js
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
// wgpu-devices.js
|
2 |
+
|
3 |
+
export async function initializeWebGPU(navigator, adapter, canvas) {
|
4 |
+
const context = canvas.getContext('webgpu');
|
5 |
+
const device = await adapter?.requestDevice();
|
6 |
+
if (!device) {
|
7 |
+
alert('need a browser that supports WebGPU');
|
8 |
+
return { device: null, context: null, presentationFormat: null };
|
9 |
+
}
|
10 |
+
|
11 |
+
const presentationFormat = navigator.gpu.getPreferredCanvasFormat();
|
12 |
+
context.configure({
|
13 |
+
device,
|
14 |
+
format: presentationFormat,
|
15 |
+
});
|
16 |
+
|
17 |
+
return { device, context, presentationFormat };
|
18 |
+
}
|