Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
include:
- os: ubuntu-26.04
browser: chrome
- os: self-hosted
browser: chrome
# - os: windows-latest
# browser: chrome

Expand Down Expand Up @@ -49,6 +51,15 @@ jobs:
env:
CI: true

- name: Build and test WebGPU (self-hosted)
id: test-webgpu
if: matrix.os == 'self-hosted'
run: |
xvfb-run --auto-servernum --server-args="-screen 0 1920x1080x24" bash -c 'CI=true npm run test -- --project=unit-tests-webgpu'
continue-on-error: true
env:
CI: true

- name: Build and test (Ubuntu)
id: test
if: matrix.os == 'ubuntu-26.04'
Expand Down Expand Up @@ -78,5 +89,5 @@ jobs:
env:
CI: true
- name: fail job if tests failed
if: steps.test.outcome != 'success'
if: steps.test.outcome == 'failure' || steps.test-webgpu.outcome == 'failure'
run: exit 1
12 changes: 12 additions & 0 deletions src/core/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,18 @@ export default p5;
* }
*/

/**
* Makes `createCanvas(w, h, WEBGPU)` throw an error instead of falling back
* to WebGL when WebGPU isn't available. The default is `false`.
*
* ```js
* p5.disableWebGLFallback = true;
* ```
*
* @static
* @property {Boolean} disableWebGLFallback
*/

/**
* Loads a p5.js library.
*
Expand Down
6 changes: 6 additions & 0 deletions src/core/rendering.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ function rendering(p5, fn) {

if (!renderers[renderer] && typeof renderer === 'string') {
if (renderer === constants.WEBGPU) {
if (p5.disableWebGLFallback) {
throw new Error('To create a WEBGPU canvas, add the WebGPU add-on to your project.');
}
p5.FES.log`To create a WEBGPU canvas, add the WebGPU add-on to your project.`();
if (renderers[constants.WEBGL]) {
p5.FES.log`Falling back to WebGL renderer.`();
Expand Down Expand Up @@ -176,6 +179,9 @@ function rendering(p5, fn) {
if (selectedRenderer !== constants.WEBGPU) {
throw new Error('Failed to create canvas.');
}
if (p5.disableWebGLFallback) {
throw e;
}
p5.FES.log`${e.message} Falling back to WebGL renderer.`();
return this.createCanvas(w, h, constants.WEBGL, ...args);
});
Expand Down
1 change: 1 addition & 0 deletions test/unit/visual/cases/webgpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { visualSuite, visualTest } from '../visualTest';
import rendererWebGPU from '../../../../src/webgpu/p5.RendererWebGPU';

p5.registerAddon(rendererWebGPU);
p5.disableWebGLFallback = true;

visualSuite('WebGPU', function () {
visualSuite('Shaders', function () {
Expand Down
1 change: 1 addition & 0 deletions test/unit/webgpu/p5.Framebuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import p5 from '../../../src/app.js';
import rendererWebGPU from '../../../src/webgpu/p5.RendererWebGPU';

p5.registerAddon(rendererWebGPU);
p5.disableWebGLFallback = true;

suite('WebGPU p5.Framebuffer', function () {
let myp5;
Expand Down
1 change: 1 addition & 0 deletions test/unit/webgpu/p5.RendererWebGPU.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import rendererWebGPU from '../../../src/webgpu/p5.RendererWebGPU';
import { vi } from 'vitest';

p5.registerAddon(rendererWebGPU);
p5.disableWebGLFallback = true;

suite('WebGPU p5.RendererWebGPU', function () {
let myp5;
Expand Down
1 change: 1 addition & 0 deletions test/unit/webgpu/p5.Shader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import p5 from '../../../src/app.js';
import rendererWebGPU from '../../../src/webgpu/p5.RendererWebGPU';

p5.registerAddon(rendererWebGPU);
p5.disableWebGLFallback = true;

suite('WebGPU p5.Shader', function () {
var myp5;
Expand Down
6 changes: 3 additions & 3 deletions vitest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ export default defineConfig({
'--no-sandbox',
'--headless=new',
'--enable-unsafe-webgpu',
'--use-vulkan=swiftshader',
'--use-webgpu-adapter=swiftshader',
'--use-angle=vulkan'
'--use-gl=angle',
'--use-angle=gl-egl',
'--use-cmd-decoder=passthrough'
]
}
: { channel: 'chromium' }
Expand Down
Loading