Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

BitcountNode - 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

Open
cmhhelgeson wants to merge 11 commits into mrdoob:dev
base: dev
Choose a base branch
Loading
from cmhhelgeson:bit_count_functions
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
19 changes: 2 additions & 17 deletions examples/jsm/tsl/display/SSGINode.js
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { RenderTarget, Vector2, TempNode, QuadMesh, NodeMaterial, RendererUtils, MathUtils } from 'three/webgpu';
import { clamp, normalize, reference, nodeObject, Fn, NodeUpdateType, uniform, vec4, passTexture, uv, logarithmicDepthToViewZ, viewZToPerspectiveDepth, getViewPosition, screenCoordinate, float, sub, fract, dot, vec2, rand, vec3, Loop, mul, PI, cos, sin, uint, cross, acos, sign, pow, luminance, If, max, abs, Break, sqrt, HALF_PI, div, ceil, shiftRight, convertToTexture, bool, getNormalFromDepth, interleavedGradientNoise } from 'three/tsl';
import { clamp, normalize, reference, nodeObject, Fn, NodeUpdateType, uniform, vec4, passTexture, uv, logarithmicDepthToViewZ, viewZToPerspectiveDepth, getViewPosition, screenCoordinate, float, sub, fract, dot, vec2, rand, vec3, Loop, mul, PI, cos, sin, uint, cross, acos, sign, pow, luminance, If, max, abs, Break, sqrt, HALF_PI, div, ceil, shiftRight, convertToTexture, bool, getNormalFromDepth, bitCount, interleavedGradientNoise } from 'three/tsl';


const _quadMesh = /*@__PURE__*/ new QuadMesh();
const _size = /*@__PURE__*/ new Vector2();
Expand Down Expand Up @@ -431,22 +432,6 @@ class SSGINode extends TempNode {
]
} );

const bitCount = Fn( ( [ value ] ) => {

const v = uint( value );
v.assign( v.sub( v.shiftRight( uint( 1 ) ).bitAnd( uint( 0x55555555 ) ) ) );
v.assign( v.bitAnd( uint( 0x33333333 ) ).add( v.shiftRight( uint( 2 ) ).bitAnd( uint( 0x33333333 ) ) ) );

return v.add( v.shiftRight( uint( 4 ) ) ).bitAnd( uint( 0xF0F0F0F ) ).mul( uint( 0x1010101 ) ).shiftRight( uint( 24 ) );

} ).setLayout( {
name: 'bitCount',
type: 'uint',
inputs: [
{ name: 'value', type: 'uint' }
]
} );

const horizonSampling = Fn( ( [ directionIsRight, RADIUS, viewPosition, slideDirTexelSize, initialRayStep, uvNode, viewDir, viewNormal, n ] ) => {

const STEP_COUNT = this.stepCount.toConst();
Expand Down
8 changes: 4 additions & 4 deletions examples/webgpu_compute_reduce.html
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ <h3 id="panel-title" style="flex: 0 0 auto;">Subgroup Reduction Explanation</h3>
<script type="module">

import * as THREE from 'three/webgpu';
import { instancedArray, Loop, If, vec3, dot, clamp, storage, uvec4, subgroupAdd, uniform, uv, uint, float, Fn, vec2, invocationLocalIndex, invocationSubgroupIndex, uvec2, floor, instanceIndex, workgroupId, workgroupBarrier, workgroupArray, subgroupSize, select, log2 } from 'three/tsl';
import { instancedArray, Loop, If, vec3, dot, clamp, storage, uvec4, subgroupAdd, uniform, uv, uint, float, Fn, vec2, invocationLocalIndex, invocationSubgroupIndex, uvec2, floor, instanceIndex, workgroupId, workgroupBarrier, workgroupArray, subgroupSize, select, countTrailingZeros } from 'three/tsl';

import WebGPU from 'three/addons/capabilities/WebGPU.js';

Expand Down Expand Up @@ -831,12 +831,12 @@ <h3 id="panel-title" style="flex: 0 0 auto;">Subgroup Reduction Explanation</h3>

// Multiple approaches here
// log2(subgroupSize) -> TSL log2 function
// countTrailingZeros/findLSB(subgroupSize) -> Currently unsupported function in TSL that counts trailing zeros in number bit representation
// countTrailingZeros/findLSB(subgroupSize) -> TSL function that counts trailing zeros in number bit representation
// Can technically petition GPU for subgroupSize in shader and calculate logs on CPU at cost of shader being generalizable across devices
// May also break if subgroupSize changes when device is lost or if program is rerun on lower power device
const subgroupSizeLog = uint(log2(float(subgroupSize)) ).toVar( 'subgroupSizeLog' );
const subgroupSizeLog = countTrailingZeros(subgroupSize ).toVar( 'subgroupSizeLog' );
const spineSize = uint( workgroupSize ).shiftRight( subgroupSizeLog );
const spineSizeLog = uint(log2(float(spineSize)) ).toVar( 'spineSizeLog' );
const spineSizeLog = countTrailingZeros(spineSize ).toVar( 'spineSizeLog' );


// Align size to powers of subgroupSize
Expand Down
6 changes: 6 additions & 0 deletions src/Three.TSL.js
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export const batch = TSL.batch;
export const bentNormalView = TSL.bentNormalView;
export const billboarding = TSL.billboarding;
export const bitAnd = TSL.bitAnd;
export const bitCount = TSL.bitCount;
export const bitNot = TSL.bitNot;
export const bitOr = TSL.bitOr;
export const bitXor = TSL.bitXor;
Expand Down Expand Up @@ -136,6 +137,9 @@ export const context = TSL.context;
export const convert = TSL.convert;
export const convertColorSpace = TSL.convertColorSpace;
export const convertToTexture = TSL.convertToTexture;
export const countLeadingZeros = TSL.countLeadingZeros;
export const countOneBits = TSL.countOneBits;
export const countTrailingZeros = TSL.countTrailingZeros;
export const cos = TSL.cos;
export const cross = TSL.cross;
export const cubeTexture = TSL.cubeTexture;
Expand Down Expand Up @@ -180,6 +184,8 @@ export const expression = TSL.expression;
export const faceDirection = TSL.faceDirection;
export const faceForward = TSL.faceForward;
export const faceforward = TSL.faceforward;
export const findLSB = TSL.findLSB;
export const findMSB = TSL.findMSB;
export const float = TSL.float;
export const floatBitsToInt = TSL.floatBitsToInt;
export const floatBitsToUint = TSL.floatBitsToUint;
Expand Down
1 change: 1 addition & 0 deletions src/nodes/TSL.js
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export * from './core/MRTNode.js';

// math
export * from './math/BitcastNode.js';
export * from './math/BitcountNode.js';
export * from './math/Hash.js';
export * from './math/MathUtils.js';
export * from './math/TriNoise3D.js';
Expand Down
Loading

AltStyle によって変換されたページ (->オリジナル) /