Skip to content

Add deviceTypes API for WebGPU support #176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 26, 2025
Merged

Add deviceTypes API for WebGPU support #176

merged 8 commits into from
Jun 26, 2025

Conversation

marklundin
Copy link
Member

@marklundin marklundin commented Jun 23, 2025

This PR adds a new deviceTypes prop to the Application instance which will set the graphics device precedence correctly

<Application deviceTypes={["webgpu", "webgl2"]} />

This follows the same behaviour as the engine/editor taking the first successfully created graphics device. Also incldues documentation

Note the in 2.8.0 the engine is using WebGPU shaders, but you will likely still need the glslang transpiler for scripts and custom shaders when usign WebGPU. In this case pass glslangUrl?: string; and twgslUrl?: string; as graphicsDevice options and the engine will automatically transpile. This will become unnecesary once script shaders are converted.

  • Introduced a new deviceTypes prop in the Application component to specify graphics device types, allowing for fallback options between WebGPU and WebGL2.
  • Updated the Application documentation to include details on the new deviceTypes prop and its usage.
  • Enhanced the Application component to initialize the graphics device based on the specified device types.
  • changeset

- Introduced a new `deviceTypes` prop in the Application component to specify graphics device types, allowing for fallback options between WebGPU and WebGL2.
- Updated the Application documentation to include details on the new `deviceTypes` prop and its usage.
- Enhanced the Application component to initialize the graphics device based on the specified device types.

* changeset
@marklundin marklundin self-assigned this Jun 23, 2025
@marklundin marklundin added enhancement New feature or request React labels Jun 23, 2025
Copy link

changeset-bot bot commented Jun 23, 2025

🦋 Changeset detected

Latest commit: 7478e5a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@playcanvas/react Minor
@playcanvas/blocks Major
docs Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

pkg-pr-new bot commented Jun 23, 2025

Open in StackBlitz

npm i https://pkg.pr.new/@playcanvas/blocks@176
npm i https://pkg.pr.new/@playcanvas/react@176

commit: 7478e5a

- Updated Application component tests to pass the new deviceTypes prop, ensuring compatibility with the latest graphics device initialization.
- Modified Container, Entity, Screen, and Script component tests to include deviceTypes for consistent testing across components.
- Cleaned up unused code and improved test structure for better readability and maintainability.
…imize graphics device initialization

- Set default value for deviceTypes to [DEVICETYPE_WEBGL2] in the ApplicationWithoutCanvas component.
- Introduced memoization for deviceTypes to enhance performance during graphics device creation.
- Updated graphics device initialization to use memoized deviceTypes for improved consistency.
- Added a test case to warn when an invalid deviceTypes prop is provided, ensuring proper validation.
- Refactored the Application component to improve graphics device initialization and memoization of deviceTypes.
- Updated the create-graphics-device utility to allow explicit device type specification without injecting additional devices.
- Adjusted validation error messages for deviceTypes to provide clearer feedback on incorrect usage.
- Clarified the description of the deviceTypes prop to specify its role in determining the graphics device order.
- Added information about the "null" device type for testing purposes, enhancing the documentation's comprehensiveness.
@marklundin marklundin merged commit 894ca08 into main Jun 26, 2025
5 checks passed
@marklundin marklundin deleted the feat-device-types branch June 26, 2025 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request React
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant