Skip to content
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

Fix: Incorrect usage of 'await' in WebGPU.js #28124

Closed
wants to merge 1 commit into from
Closed

Fix: Incorrect usage of 'await' in WebGPU.js #28124

wants to merge 1 commit into from

Conversation

puxiao
Copy link
Contributor

@puxiao puxiao commented Apr 12, 2024

The previous code was very poorly readable.

isAvailable seems to be a Boolean value, but why does it suddenly become a GPUAdapter later?


The most critical error is: await can only run in async function !


If you use vite , when you write this line of code:

const renderer = new WebGPURenderer()

You will receive an error like this:

Top-level await is not available in the configured target environment ("chrome87", "edge88", "es2020", "firefox78", "safari14" + 2 overrides)

----------------

By the way, I don't understand the meaning of getStaticAdapter() at all. It feels completely unnecessary.

@puxiao puxiao changed the title Update WebGPU.js Fix: Incorrect usage of 'await' in WebGPU.js Apr 12, 2024
@Mugen87
Copy link
Collaborator

Mugen87 commented Apr 12, 2024

We do not fix top-level await usage, see #28107. This needs to be solved on bundler side.

BTW: Nothing at top-level await usage is "incorrect". It is a restriction of bundlers.

@puxiao
Copy link
Contributor Author

puxiao commented Apr 12, 2024

I know it can be solved in the following way, but I still don't quite understand why.

vite.confit.js

export default defineConfig({
    ...
    optimizeDeps: {
        esbuildOptions: {
            target: 'esnext'
        }
    }
})

@Mugen87
Copy link
Collaborator

Mugen87 commented Apr 12, 2024

Sorry, but the change can't be merged. This breaks all example code.

@Mugen87 Mugen87 closed this Apr 12, 2024
@wcandillon
Copy link
Contributor

@Mugen87 We are running three.js on Hermes which is very unlikely to support top level await anytime soon. You can see a demo of it here: https://x.com/wcandillon/status/1825862686300672124
To run such a demo, we need to apply to two tiny patches:

Do you think it's something that we could merge upstream eventually?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants