-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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
Provide a WebGPU build that re-exports from three #29156
Comments
+1 from me. Besides the missing exports, I think what also should be clarified is how libraries are supposed to start adding support for WebGPU – not everyone will be able/willing to provide/maintain separate bundles for webgl vs. webgpu. That unclarity includes three.js examples themself – an example:
|
+1 from me as well but there is a forum topic which suggests that this might not be happening. |
My feeling here would be that we may need to work out a way for GLTFExporter not to import a renderer. Either to require pre-processing the scene, or specifying some configuration on the exporter that provides a decompress implementation or renderer. |
How about doing something like this: const exporter = new THREE.GLTFExporter();
exporter.setTextureUtils( utils );
|
To clarify the proposal in this issue with regards to the forums post
In my mind this issue is not in opposition to having another WebGPURenderer build that does not contain WebGLRenderer exports, this would primarily support use cases where bundlers are not used. However, using that same build for bundler use cases is problematic, which is why this issue is asking for the Something we can anticipate will be common during the transition period is libraries exporting both WebGLRenderer and WebGPURenderer versions of utilities. Without the proposed change, libraries cannot easily do this. |
How does this work? Does the project need a specific configuration in its |
I imagine we could approach changing
|
How about we introduce a new package? Package We'd have to figure out how to publish two packages from a single repo... Then, maybe in 10 years (😶)... We could make both the same? /cc @sunag |
I think that would force each thing in the ecosystem to also provide multiple packages, instead of being able to support "three" with WebGL and WebGPU with one ecosystem package... My opinion is that re-exporting with WebGPU, making sure the code in three supports both systems, and providing examples for how third-party code supports both systems would be better. |
Yes, I am worried If we had no other solution, then publishing two versions (not two packages) under The suggestion from @isaac-mason sounds workable to me, @mrdoob do you have |
Another idea is re-exporting from |
I like @CodyJasonBennett's proposal in #29404. Possibly related... do we need/want the |
I stumbled upon this post after upgrading our three version to 0.169 from 0.167 and switching around our exports along with our ts config paths and vite config alias. We currently are using the WebGPURenderer entirely throughout our project. vite config:
ts config:
I wasn't sure if we were doing this entirely correct, but everything seemed to work fine. By doing this along with changing a few import statements, it also allowed us to get rid of the "multiple instances of webgpu being imported" that we had originally. The only issue we face at the moment is when importing and using the GLTFExporter:
Since the GLTFExporter uses the decompress method of TextureUtils, we get the error node_modules/three/examples/jsm/utils/TextureUtils.js (10:1): "WebGLRenderer" is not exported by "node_modules/three/src/Three.WebGPU.js", imported by "node_modules/three/examples/jsm/utils/TextureUtils.js". Which stems from this line in the decompress method:
If we comment out that line, it removes the error and we are then able to use the GLTFExporter without any issues. I see that there is the TextureUtilsGPU.js file now, but that it's not used anywhere within the three code. I apologize if I'm missing something obvious here, but wanted to bump this thread to showcase how we are unable to use the GLTFExporter at the moment unless we comment out that line. For the time being, we have created a mod of the GLTFExporter where the only change we make to it is replacing:
with
And this seems to work. Anyways, thanks for taking another look into this. |
Hoping to fix GLTFExporter with: But there are more issues still to resolve in that PR. And, I think we do need to agree on #29404 or something along those lines, so that custom vite configs are not required. |
Bumping this as a solution like #29404 is crucial for us to move forward with the WebGPURenderer. The approach I suggested in this comment is more of a temporary patch that sidesteps the core issue. A solid implementation is needed to ensure the WebGPURenderer integrates seamlessly with the Three.js ecosystem and its libraries. Could we consider advancing with the PR of Cody? /cc @sunag @mrdoob @Mugen87 |
I'm okay with #29404. If the merge conflicts are resolved, we can make a merge from my point of view. |
Not sure if this is still a point of discussion - but I was just considering how much nicer it would be to have a completely distinct package for the gpu stuff. It's a huge head-ache trying to make sure you don't accidentally import Obviously, this might be super hard to implement in practice - but figured I'd call out that I was just wishing for this (which is how I found this issue) |
@LukeWood #29404 will address that head-ache by making it completely fine to use renderer agnostic exports from |
Oh fantastic - ok then problem solved from my perspective. Vector, Box, Frustrum and Sphere have been the sources of my woes in this area. |
(Please note, my bold text below is only highlighting important details that I believe need high consideration)
Simpler solution:
This approach
But the best thing about this approach is that the huge amounts of projects that already import from import {WebGLRenderer} from 'three' to this, import {WebGPURenderer} from 'three' or even to the following if they want to use both (f.e. libraries that provide multiple render modes): import {WebGLRenderer, WebGPURenderer} from 'three' Another thing is, we probably all expect the I know a big software company (you might use their products every day) has a build step that ingests the |
@CodyJasonBennett The solution in #29404 still requires people to update their builds (f.e. at some-big-company-you-know, this is a pain right now). Some of those builds produce outputs for internal org use, so now they are forced to figure out how to handle the webgpu path, when really the whole issue could be 100% avoided without build changes anywhere. What do you think about the approach of the previous comment? It would allow all build setups to continue working as-is. |
That is mistaken. #29404 is one of a few ways that require no build configuration. I suspect the issue is exactly they were relying on
Merging everything to |
The company is not SpaceX. And yes, the change in #29404 requires a build configuration update because the No one is trying to extort you! |
About top-level await, common bundlers support ESM spec nowadays, including top-level await. I agree though that if someone has a bundler or build setup that does not understand top-level await, then they will need to update their build. Here's a question: Can we replace top-level await with something else? For example, move it into a function, f.e. inside of a Loader. If so, then the problem will be solved in a better way. |
And again, because I suggested an improvement, does not mean anyone is trying to extort you @CodyJasonBennett. The purpose of this conversation is to resolve a very real issue. |
Again, you are mistaken or conflating two issues. |
I see top-level await (TLA) has already been fixed in Can you please briefly outline the reasons that WebGPURenderer should not be exported from |
Although I have personal reservations about putting experimental code into core (which is part of the absolute mess that created this issue), the technical reasons are as follows, which I explained further above in context:
This list is exhaustive from a purely technical POV, but the general issue of migration and general API is ongoing, and it's a massive one. We've dealt with some of the scarier issues, like #26140, and now have I will yet again maintain that it is not needed to resolve this issue, and #29404 or its outlined alternatives are sufficient. I maintain that these are two separate issues, as three API does not reflect the supposed configuration you were relying on, and the recommendation of configuration and even use in production is irresponsible and misleading. As I've seen trouble historically from unnamed companies and discourse devolve into useless conjecture, I'm willing to bet $10,000 this is and will remain the case and limit to the latest major of all build tools and runtimes (Webpack, Parcel, Rollup, Vite, ESBuild, Rspack, Turbo, SWC, Nx, Metro). As a simplification, this enables ES2021+ ESM-only output. I will leave this only until February, when I'm expecting WebGPU to become a living standard, and we can move to commit to this once implementations catch up. You will find that this is indeed very difficult, and what I'm offering is both a correction and stepping stone to a final API. |
An API could be marked "experimental" in
I believe this was fixed already. This test repo shows that esbuild works with target es2020, indicating no TLA is used anywhere.
That's a good problem to solve. I thought tree shaking was irrespective of import/export paths. Is that not true? #29404 is definitely better than what we have currently because it provides a path to having both webgl and webgpu instead of a difficult split, however it still requires build tool updates downstream. I'm just expressing that if we can upgrade with no build changes required, it would be great: we'd just update the |
I have elaborated now several times in explicit detail, and it's clear you are simply manipulating the project into pulling the trigger on merging the WebGL/WebGPU entrypoints because you, or a company that cannot be named, has configuration that incidentally relied on this being the API, after a string of irresponsible messaging that created this problem in the first place. That is not the purpose of this issue nor the current state of three API or any surrounding implementation (be it browsers, implementations, tooling—all of it). I will no longer entertain this here and expect any further progress I have enumerated to be continued elsewhere. You should have the direction you need to migrate to stable API, or continue configuration like before. |
@CodyJasonBennett I get the impression you don't want to discuss this, thanks for the input. I made a pull request to show the concept: If it is decided that this proposal is the desired path, and more work is needed, I'll be willing to update it. |
Lets focus on #29404 |
Description
When using the WebGPU build introduced in r167 with vite, using recommended aliases configuration, I am unable to use renderer agnostic exports from libraries that also have webgl imports. Bundlers will have errors attempting to import webgl specific imports that are not exported by the webgpu build.
Solution
If the three/webgpu build re-exported from three, aliases would not be required to use the webgpu build with bundlers, and libraries could export both webgl and webgpu utilities that import from both three and three/webgpu.
Alternatives
A build that has both webgl and webgpu exports could solve some issues, but this is not as desirable as the proposed solution as bundler aliases would still be required to prevent duplication issues.
Additional context
https://twitter.com/onirenaud/status/1824688713542341119
The text was updated successfully, but these errors were encountered: