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

WebGPURenderer: OperatorNode Add unary operator support #27641

Merged
merged 2 commits into from
Jan 29, 2024
Merged
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
2 changes: 1 addition & 1 deletion examples/jsm/nodes/Nodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export { NodeUtils };
// math
export { default as MathNode, PI, PI2, EPSILON, INFINITY, radians, degrees, exp, exp2, log, log2, sqrt, inverseSqrt, floor, ceil, normalize, fract, sin, cos, tan, asin, acos, atan, abs, sign, length, lengthSq, negate, oneMinus, dFdx, dFdy, round, reciprocal, trunc, fwidth, bitcast, atan2, min, max, mod, step, reflect, distance, difference, dot, cross, pow, pow2, pow3, pow4, transformDirection, mix, clamp, saturate, refract, smoothstep, faceForward, cbrt } from './math/MathNode.js';

export { default as OperatorNode, add, sub, mul, div, remainder, equal, lessThan, greaterThan, lessThanEqual, greaterThanEqual, and, or, xor, bitAnd, bitOr, bitXor, shiftLeft, shiftRight } from './math/OperatorNode.js';
export { default as OperatorNode, add, sub, mul, div, remainder, equal, lessThan, greaterThan, lessThanEqual, greaterThanEqual, and, or, not, xor, bitAnd, bitNot, bitOr, bitXor, shiftLeft, shiftRight } from './math/OperatorNode.js';
export { default as CondNode, cond } from './math/CondNode.js';
export { default as HashNode, hash } from './math/HashNode.js';

Expand Down
18 changes: 13 additions & 5 deletions examples/jsm/nodes/math/OperatorNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class OperatorNode extends TempNode {
const bNode = this.bNode;

const typeA = aNode.getNodeType( builder );
const typeB = bNode.getNodeType( builder );
const typeB = typeof bNode !== 'undefined' ? bNode.getNodeType( builder ) : null;

if ( typeA === 'void' || typeB === 'void' ) {

Expand All @@ -47,11 +47,11 @@ class OperatorNode extends TempNode {

return typeA;

} else if ( op === '&' || op === '|' || op === '^' || op === '>>' || op === '<<' ) {
} else if ( op === '~' || op === '&' || op === '|' || op === '^' || op === '>>' || op === '<<' ) {

return builder.getIntegerType( typeA );

} else if ( op === '==' || op === '&&' || op === '||' || op === '^^' ) {
} else if ( op === '!' || op === '==' || op === '&&' || op === '||' || op === '^^' ) {

return 'bool';

Expand Down Expand Up @@ -108,7 +108,7 @@ class OperatorNode extends TempNode {
if ( type !== 'void' ) {

typeA = aNode.getNodeType( builder );
typeB = bNode.getNodeType( builder );
typeB = typeof bNode !== 'undefined' ? bNode.getNodeType( builder ) : null;

if ( op === '<' || op === '>' || op === '<=' || op === '>=' || op === '==' ) {

Expand Down Expand Up @@ -154,7 +154,7 @@ class OperatorNode extends TempNode {
}

const a = aNode.build( builder, typeA );
const b = bNode.build( builder, typeB );
const b = typeof bNode !== 'undefined' ? bNode.build( builder, typeB ) : null;

const outputLength = builder.getTypeLength( output );
const fnOpSnippet = builder.getFunctionOperator( op );
Expand All @@ -177,6 +177,10 @@ class OperatorNode extends TempNode {

return builder.format( `${ builder.getMethod( 'greaterThanEqual' ) }( ${ a }, ${ b } )`, type, output );

} else if ( op === '!' || op === '~' ) {

return builder.format( `(${op}${a})`, typeA, output );

} else if ( fnOpSnippet ) {

return builder.format( `${ fnOpSnippet }( ${ a }, ${ b } )`, type, output );
Expand Down Expand Up @@ -236,8 +240,10 @@ export const lessThanEqual = nodeProxy( OperatorNode, '<=' );
export const greaterThanEqual = nodeProxy( OperatorNode, '>=' );
export const and = nodeProxy( OperatorNode, '&&' );
export const or = nodeProxy( OperatorNode, '||' );
export const not = nodeProxy( OperatorNode, '!' );
export const xor = nodeProxy( OperatorNode, '^^' );
export const bitAnd = nodeProxy( OperatorNode, '&' );
export const bitNot = nodeProxy( OperatorNode, '~' );
export const bitOr = nodeProxy( OperatorNode, '|' );
export const bitXor = nodeProxy( OperatorNode, '^' );
export const shiftLeft = nodeProxy( OperatorNode, '<<' );
Expand All @@ -256,8 +262,10 @@ addNodeElement( 'lessThanEqual', lessThanEqual );
addNodeElement( 'greaterThanEqual', greaterThanEqual );
addNodeElement( 'and', and );
addNodeElement( 'or', or );
addNodeElement( 'not', not );
addNodeElement( 'xor', xor );
addNodeElement( 'bitAnd', bitAnd );
addNodeElement( 'bitNot', bitNot );
addNodeElement( 'bitOr', bitOr );
addNodeElement( 'bitXor', bitXor );
addNodeElement( 'shiftLeft', shiftLeft );
Expand Down