-
-
Notifications
You must be signed in to change notification settings - Fork 36.1k
TSL: Add bitCount functions
#31990
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
TSL: Add bitCount functions
#31990
Conversation
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
|
Related: There is a custom three.js/examples/jsm/tsl/display/SSGINode.js Lines 448 to 462 in 2a02884
It's great to see WGSL support! How about providing a built-in |
In hindsight, I think it's possible to add polyfills for the other functions as well, so I will get on doing that. The link you provided should be useful in generating the necessary functions. |
|
I'm going to fix the extant issues like documentation, but I'm also going to draft this PR so I can implement a polyfill approach. Basically, I'd be adding GLSL polyfills similar to how the WGSLNodeBuilder has polyfills for certain functions. Would this approach be desired, or would a different approach be preferred ( for instance, generating different nodes depending on the renderer's backend ). Personally, I'd prefer polyfilling in the GLSLNodeBuilder to keep the node code simpler for a simple mathematical operation. |
Then I suggest you start with that approach so we can see how it ends up in code. |
|
Nevermind, we can just case the i32 to a u32 using the GLSL bitcast functionality. |
|
Test Examples
https://raw.githack.com/cmhhelgeson/three.js/bit_count_example/examples/webgpu_bitcount.html
Existing SSGI Example with forceWebGL set to true as example. Note how the existing SSGI implementation is significantly more noisy than the WebGPU example. https://raw.githack.com/cmhhelgeson/three.js/ssgi_test/examples/webgpu_postprocessing_ssgi.html |
What deviations are you seeing on your system? |
a3fe872 to
6650be0
Compare
4eabc26 to
a238659
Compare
|
Is it possible that #32091 is affecting the ability of displacementmap to pass its test? I'm not sure if the screenshots were updated before or after the light scattering PR, as that's the only reason I could think as to why materials_displacement is failing despite not activating the SSGINode. |
07c1c38 to
b67107c
Compare
|
I really don't know what I keep on getting strange E2E errors like E2E testing stalling for dozens of minutes or a legacy WebGLRenderer example failing when the changes are in the WebGPURenderer. |
A rerun solved the issue. It seems there are still some fragile examples like |
bitCount functions
I see the flickering you're talking about when zooming in on the SSGI. I'm a little bit perplexed that the results are so different, especially for a native function that should be executing the same functionality. I'll look into it and revert SSGI if I can't find the issue. WebGPUBackend Bitcount Test: WebGLBackend Bitcount Test: |
After thinking about it I think that's not sufficient. If you can't find the root cause, it's best to not use the native |
|
Hasty example made to compare WebGL and WebGPU output for values between 1-2000 Code for hasty example: |
I checked countOneBits and the bitCount fallback against each other multiple times and could not find a difference in the output, so for now I'm going to specify in BitcountNode that the fallback will be used in both WebGPU and WebGL. |
|
@Mugen87 I believe the issue was just that the branch was old and not fully rebased onto dev. The example no longer exhibits flickering. I think this along with the extra validation I did of the bitCount functionality should be sufficient. |
…Count helper function names
…component wise bitCounts rather than accumulative bitCounts
b65441e to
4d8ac8c
Compare
|
@Mugen87 Sorry to re-ping but just to reiterate, after testing of the functionality across the WebGL and WebGPU backend, I discovered that the issue was with the branch and not with the code itself. Accordingly, I rebased this branch onto dev to get the most up to date version of the SSGINode, then applied the BitcountNode to the SSGI. As a result the output no longer exhibits the pronounced flickering at the bottom edge of the box on the left. |
|
Got it! I'll revisit the PR next week! |
Description
Add countTrailingZeros, countLeadingZeros, and countOneBits to TSL. Ideally, this functionality would also be accessible through the WebGLBackend, but I'm not sure what the status or likelihood is of the GLSL 3.1 functionality getting added to WebGL anytime in the future ( see KhronosGroup/WebGL#3714 ).
The impetus for implementing these functions is that they're notionally more concise and/or performant than equivalent operations ( log2, directly bit shifting, etc ).
I've also implemented each of these functions GLSL equivalents (findLSB, findMSB, bitCount) as aliases for the GLSL to TSL transpiration process. If it's preferred by the maintainers, we can get rid of the aliases and/or use the NodeBuilders to specify how the bitCount functions get constructed instead.