Skip to content

Commit

Permalink
refactor(shader-ast-js): update/extend vector pool handling
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Aug 14, 2023
1 parent 6137e7a commit 1c22d0c
Show file tree
Hide file tree
Showing 14 changed files with 426 additions and 416 deletions.
45 changes: 26 additions & 19 deletions packages/shader-ast-js/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { mat22n, mat33n, mat44n } from "@thi.ng/matrices/matn";
import { mat22v, mat33v, mat44v } from "@thi.ng/matrices/matv";
import { ZERO3, ZERO4 } from "@thi.ng/vectors/api";
import { fromBVec2, fromBVec3, fromBVec4 } from "@thi.ng/vectors/convert";
import { setN2, setN3, setN4 } from "@thi.ng/vectors/setn";
import { setVN3, setVN4 } from "@thi.ng/vectors/setvn";
import { setVV4 } from "@thi.ng/vectors/setvv";
import {
Expand Down Expand Up @@ -43,9 +42,17 @@ import {
POOL_VEC4,
} from "./pool.js";

const $2 = POOL_VEC2.next.bind(POOL_VEC2);
const $3 = POOL_VEC3.next.bind(POOL_VEC3);
const $4 = POOL_VEC4.next.bind(POOL_VEC4);
const { next: $2, uniform: $n2 } = POOL_VEC2;
const { next: $3, uniform: $n3 } = POOL_VEC3;
const { next: $4, uniform: $n4 } = POOL_VEC4;

const { next: $i2, uniform: $ni2 } = POOL_IVEC2;
const { next: $i3, uniform: $ni3 } = POOL_IVEC3;
const { next: $i4, uniform: $ni4 } = POOL_IVEC4;

const { next: $u2, uniform: $nu2 } = POOL_UVEC2;
const { next: $u3, uniform: $nu3 } = POOL_UVEC3;
const { next: $u4, uniform: $nu4 } = POOL_UVEC4;

// TODO texture lookups
// all texture fns currently return [0,0,0,0] or 0
Expand All @@ -69,20 +76,20 @@ export const JS_DEFAULT_ENV: JSEnv = {
vec2: VEC2(POOL_VEC2),
vec2b: (v) => fromBVec2($2(), v),
vec2i: identity,
vec2n: (n) => setN2($2(), n),
vec2n: $n2,
vec2u: identity,

vec3: VEC3(POOL_VEC3),
vec3b: (v) => fromBVec3($3(), v),
vec3i: identity,
vec3n: (n) => setN3($3(), n),
vec3n: $n3,
vec3u: identity,
vec3vn: (a, n) => setVN3($3(), a, n),

vec4: VEC4(POOL_VEC4),
vec4b: (v) => fromBVec4($4(), v),
vec4i: identity,
vec4n: (n) => setN4($4(), n),
vec4n: $n4,
vec4u: identity,
vec4vn: (a, n) => setVN4($4(), a, n),
vec4vnn: (a, z, w) => setVV4($4(), a, [z, w]),
Expand Down Expand Up @@ -114,28 +121,28 @@ export const JS_DEFAULT_ENV: JSEnv = {
bvec4n: (n) => ((n = !!n), [n, n, n, n]),

ivec2: IVEC2,
ivec2b: (v) => fromBVec2([], v),
ivec2n: (n) => [n, n],
ivec2b: (v) => fromBVec2($i2(), v),
ivec2n: $ni2,

ivec3: IVEC3,
ivec3b: (v) => fromBVec3([], v),
ivec3n: (n) => [n, n, n],
ivec3b: (v) => fromBVec3($i3(), v),
ivec3n: $ni3,

ivec4: IVEC4,
ivec4b: (v) => fromBVec4([], v),
ivec4n: (n) => [n, n, n, n],
ivec4b: (v) => fromBVec4($i4(), v),
ivec4n: $ni4,

uvec2: UVEC2,
uvec2b: (v) => fromBVec2([], v),
uvec2n: (n) => [n, n],
uvec2b: (v) => fromBVec2($u2(), v),
uvec2n: $nu2,

uvec3: UVEC3,
uvec3b: (v) => fromBVec3([], v),
uvec3n: (n) => [n, n, n],
uvec3b: (v) => fromBVec3($u3(), v),
uvec3n: $nu3,

uvec4: UVEC4,
uvec4b: (v) => fromBVec4([], v),
uvec4n: (n) => [n, n, n, n],
uvec4b: (v) => fromBVec4($u4(), v),
uvec4n: $nu4,

mat2: MAT2,
mat3: MAT3,
Expand Down
44 changes: 22 additions & 22 deletions packages/shader-ast-js/src/env/ivec2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,29 @@ import type { JSBuiltinsIntVec } from "../api.js";
import { POOL_IVEC2 } from "../pool.js";
import { VEC2 } from "./vec2.js";

const $ = POOL_IVEC2.next.bind(POOL_IVEC2);
const { next, uniform } = POOL_IVEC2;

export const IVEC2: JSBuiltinsIntVec = {
...VEC2(POOL_IVEC2),
add: (a, b) => addI2($(), a, b),
addvn: (a, b) => addNI2($(), a, b),
addnv: (a, b) => addNI2($(), b, a),
div: (a, b) => divI2($(), a, b),
divvn: (a, b) => divNI2($(), a, b),
divnv: (a, b) => divI2(null, [a, a], b),
modi: (a, b) => fmod2($(), a, b),
modivn: (a, b) => fmodN2($(), a, b),
modinv: (a, b) => fmod2(null, [a, a], b),
mul: (a, b) => mulI2($(), a, b),
mulvn: (a, b) => mulNI2($(), a, b),
mulnv: (a, b) => mulNI2($(), b, a),
sub: (a, b) => subI2($(), a, b),
subvn: (a, b) => subNI2($(), a, b),
subnv: (a, b) => subI2(null, [a, a], b),
bitand: (a, b) => bitAndI2($(), a, b),
lshift: (a, b) => lshiftI2($(), a, b),
bitnot1: (a) => bitNotI2($(), a),
bitor: (a, b) => bitOrI2($(), a, b),
rshift: (a, b) => rshiftI2($(), a, b),
bitxor: (a, b) => bitXorI2($(), a, b),
add: (a, b) => addI2(next(), a, b),
addvn: (a, b) => addNI2(next(), a, b),
addnv: (a, b) => addNI2(next(), b, a),
div: (a, b) => divI2(next(), a, b),
divvn: (a, b) => divNI2(next(), a, b),
divnv: (a, b) => divI2(null, uniform(a), b),
modi: (a, b) => fmod2(next(), a, b),
modivn: (a, b) => fmodN2(next(), a, b),
modinv: (a, b) => fmod2(null, uniform(a), b),
mul: (a, b) => mulI2(next(), a, b),
mulvn: (a, b) => mulNI2(next(), a, b),
mulnv: (a, b) => mulNI2(next(), b, a),
sub: (a, b) => subI2(next(), a, b),
subvn: (a, b) => subNI2(next(), a, b),
subnv: (a, b) => subI2(null, uniform(a), b),
bitand: (a, b) => bitAndI2(next(), a, b),
lshift: (a, b) => lshiftI2(next(), a, b),
bitnot1: (a) => bitNotI2(next(), a),
bitor: (a, b) => bitOrI2(next(), a, b),
rshift: (a, b) => rshiftI2(next(), a, b),
bitxor: (a, b) => bitXorI2(next(), a, b),
};
44 changes: 22 additions & 22 deletions packages/shader-ast-js/src/env/ivec3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,29 @@ import type { JSBuiltinsIntVec } from "../api.js";
import { POOL_IVEC3 } from "../pool.js";
import { VEC3 } from "./vec3.js";

const $ = POOL_IVEC3.next.bind(POOL_IVEC3);
const { next, uniform } = POOL_IVEC3;

export const IVEC3: JSBuiltinsIntVec = {
...VEC3(POOL_IVEC3),
add: (a, b) => addI3($(), a, b),
addvn: (a, b) => addNI3($(), a, b),
addnv: (a, b) => addNI3($(), b, a),
div: (a, b) => divI3($(), a, b),
divvn: (a, b) => divNI3($(), a, b),
divnv: (a, b) => divI3(null, [a, a, a], b),
modi: (a, b) => fmod3($(), a, b),
modivn: (a, b) => fmodN3($(), a, b),
modinv: (a, b) => fmod3(null, [a, a, a], b),
mul: (a, b) => mulI3($(), a, b),
mulvn: (a, b) => mulNI3($(), a, b),
mulnv: (a, b) => mulNI3($(), b, a),
sub: (a, b) => subI3($(), a, b),
subvn: (a, b) => subNI3($(), a, b),
subnv: (a, b) => subI3(null, [a, a, a], b),
bitand: (a, b) => bitAndI3($(), a, b),
lshift: (a, b) => lshiftI3($(), a, b),
bitnot1: (a) => bitNotI3($(), a),
bitor: (a, b) => bitOrI3($(), a, b),
rshift: (a, b) => rshiftI3($(), a, b),
bitxor: (a, b) => bitXorI3($(), a, b),
add: (a, b) => addI3(next(), a, b),
addvn: (a, b) => addNI3(next(), a, b),
addnv: (a, b) => addNI3(next(), b, a),
div: (a, b) => divI3(next(), a, b),
divvn: (a, b) => divNI3(next(), a, b),
divnv: (a, b) => divI3(null, uniform(a), b),
modi: (a, b) => fmod3(next(), a, b),
modivn: (a, b) => fmodN3(next(), a, b),
modinv: (a, b) => fmod3(null, uniform(a), b),
mul: (a, b) => mulI3(next(), a, b),
mulvn: (a, b) => mulNI3(next(), a, b),
mulnv: (a, b) => mulNI3(next(), b, a),
sub: (a, b) => subI3(next(), a, b),
subvn: (a, b) => subNI3(next(), a, b),
subnv: (a, b) => subI3(null, uniform(a), b),
bitand: (a, b) => bitAndI3(next(), a, b),
lshift: (a, b) => lshiftI3(next(), a, b),
bitnot1: (a) => bitNotI3(next(), a),
bitor: (a, b) => bitOrI3(next(), a, b),
rshift: (a, b) => rshiftI3(next(), a, b),
bitxor: (a, b) => bitXorI3(next(), a, b),
};
44 changes: 22 additions & 22 deletions packages/shader-ast-js/src/env/ivec4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,29 @@ import type { JSBuiltinsIntVec } from "../api.js";
import { POOL_IVEC4 } from "../pool.js";
import { VEC4 } from "./vec4.js";

const $ = POOL_IVEC4.next.bind(POOL_IVEC4);
const { next, uniform } = POOL_IVEC4;

export const IVEC4: JSBuiltinsIntVec = {
...VEC4(POOL_IVEC4),
add: (a, b) => addI4($(), a, b),
addvn: (a, b) => addNI4($(), a, b),
addnv: (a, b) => addNI4($(), b, a),
div: (a, b) => divI4($(), a, b),
divvn: (a, b) => divNI4($(), a, b),
divnv: (a, b) => divI4(null, [a, a, a, a], b),
modi: (a, b) => fmod4($(), a, b),
modivn: (a, b) => fmodN4($(), a, b),
modinv: (a, b) => fmod4(null, [a, a, a, a], b),
mul: (a, b) => mulI4($(), a, b),
mulvn: (a, b) => mulNI4($(), a, b),
mulnv: (a, b) => mulNI4($(), b, a),
sub: (a, b) => subI4($(), a, b),
subvn: (a, b) => subNI4($(), a, b),
subnv: (a, b) => subI4(null, [a, a, a, a], b),
bitand: (a, b) => bitAndI4($(), a, b),
lshift: (a, b) => lshiftI4($(), a, b),
bitnot1: (a) => bitNotI4($(), a),
bitor: (a, b) => bitOrI4($(), a, b),
rshift: (a, b) => rshiftI4($(), a, b),
bitxor: (a, b) => bitXorI4($(), a, b),
add: (a, b) => addI4(next(), a, b),
addvn: (a, b) => addNI4(next(), a, b),
addnv: (a, b) => addNI4(next(), b, a),
div: (a, b) => divI4(next(), a, b),
divvn: (a, b) => divNI4(next(), a, b),
divnv: (a, b) => divI4(null, uniform(a), b),
modi: (a, b) => fmod4(next(), a, b),
modivn: (a, b) => fmodN4(next(), a, b),
modinv: (a, b) => fmod4(null, uniform(a), b),
mul: (a, b) => mulI4(next(), a, b),
mulvn: (a, b) => mulNI4(next(), a, b),
mulnv: (a, b) => mulNI4(next(), b, a),
sub: (a, b) => subI4(next(), a, b),
subvn: (a, b) => subNI4(next(), a, b),
subnv: (a, b) => subI4(null, uniform(a), b),
bitand: (a, b) => bitAndI4(next(), a, b),
lshift: (a, b) => lshiftI4(next(), a, b),
bitnot1: (a) => bitNotI4(next(), a),
bitor: (a, b) => bitOrI4(next(), a, b),
rshift: (a, b) => rshiftI4(next(), a, b),
bitxor: (a, b) => bitXorI4(next(), a, b),
};
38 changes: 19 additions & 19 deletions packages/shader-ast-js/src/env/mat2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@ import { neg } from "@thi.ng/vectors/neg";
import type { JSBuiltinsMat } from "../api.js";
import { POOL_VEC4 } from "../pool.js";

const $ = POOL_VEC4.next.bind(POOL_VEC4);
const { next, uniform } = POOL_VEC4;

export const MAT2: JSBuiltinsMat = {
add: (a, b) => add22($(), a, b),
addnv: (a, b) => addN22($(), b, a),
addvn: (a, b) => addN22($(), a, b),
dec: (a) => subN22($(), a, 1),
div: (a, b) => div22($(), a, b),
divnv: (a, b) => div22(null, [a, a, a, a], b),
divvn: (a, b) => divN22($(), a, b),
add: (a, b) => add22(next(), a, b),
addnv: (a, b) => addN22(next(), b, a),
addvn: (a, b) => addN22(next(), a, b),
dec: (a) => subN22(next(), a, 1),
div: (a, b) => div22(next(), a, b),
divnv: (a, b) => div22(null, uniform(a), b),
divvn: (a, b) => divN22(next(), a, b),
idx: (a, b) => [a[b * 2], a[b * 2 + 1]],
inc: (a) => addN22($(), a, 1),
mul: (a, b) => mul22($(), a, b),
mulm: (a, b) => mulM22($(), a, b),
mulmv: (a, b) => mulV22($(), a, b),
mulnv: (a, b) => mulN22($(), b, a),
mulvm: (a, b) => mulVM22($(), a, b),
mulvn: (a, b) => mulN22($(), a, b),
sub: (a, b) => sub22($(), a, b),
sub1: (a) => neg($(), a),
subnv: (a, b) => sub22(null, [a, a, a, a], b),
subvn: (a, b) => subN22($(), a, b),
inc: (a) => addN22(next(), a, 1),
mul: (a, b) => mul22(next(), a, b),
mulm: (a, b) => mulM22(next(), a, b),
mulmv: (a, b) => mulV22(next(), a, b),
mulnv: (a, b) => mulN22(next(), b, a),
mulvm: (a, b) => mulVM22(next(), a, b),
mulvn: (a, b) => mulN22(next(), a, b),
sub: (a, b) => sub22(next(), a, b),
sub1: (a) => neg(next(), a),
subnv: (a, b) => sub22(null, uniform(a), b),
subvn: (a, b) => subN22(next(), a, b),
};
44 changes: 22 additions & 22 deletions packages/shader-ast-js/src/env/uvec2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,29 @@ import type { JSBuiltinsIntVec } from "../api.js";
import { POOL_UVEC2 } from "../pool.js";
import { VEC2 } from "./vec2.js";

const $ = POOL_UVEC2.next.bind(POOL_UVEC2);
const { next, uniform } = POOL_UVEC2;

export const UVEC2: JSBuiltinsIntVec = {
...VEC2(POOL_UVEC2),
add: (a, b) => addU2($(), a, b),
addvn: (a, b) => addNU2($(), a, b),
addnv: (a, b) => addNU2($(), b, a),
div: (a, b) => divU2($(), a, b),
divvn: (a, b) => divNU2($(), a, b),
divnv: (a, b) => divU2(null, [a, a], b),
modi: (a, b) => fmod2($(), a, b),
modivn: (a, b) => fmodN2($(), a, b),
modinv: (a, b) => fmod2(null, [a, a], b),
mul: (a, b) => mulU2($(), a, b),
mulvn: (a, b) => mulNU2($(), a, b),
mulnv: (a, b) => mulNU2($(), b, a),
sub: (a, b) => subU2($(), a, b),
subvn: (a, b) => subNU2($(), a, b),
subnv: (a, b) => subU2(null, [a, a], b),
bitand: (a, b) => bitAndU2($(), a, b),
lshift: (a, b) => lshiftU2($(), a, b),
bitnot1: (a) => bitNotU2($(), a),
bitor: (a, b) => bitOrU2($(), a, b),
rshift: (a, b) => rshiftU2($(), a, b),
bitxor: (a, b) => bitXorU2($(), a, b),
add: (a, b) => addU2(next(), a, b),
addvn: (a, b) => addNU2(next(), a, b),
addnv: (a, b) => addNU2(next(), b, a),
div: (a, b) => divU2(next(), a, b),
divvn: (a, b) => divNU2(next(), a, b),
divnv: (a, b) => divU2(null, uniform(a), b),
modi: (a, b) => fmod2(next(), a, b),
modivn: (a, b) => fmodN2(next(), a, b),
modinv: (a, b) => fmod2(null, uniform(a), b),
mul: (a, b) => mulU2(next(), a, b),
mulvn: (a, b) => mulNU2(next(), a, b),
mulnv: (a, b) => mulNU2(next(), b, a),
sub: (a, b) => subU2(next(), a, b),
subvn: (a, b) => subNU2(next(), a, b),
subnv: (a, b) => subU2(null, uniform(a), b),
bitand: (a, b) => bitAndU2(next(), a, b),
lshift: (a, b) => lshiftU2(next(), a, b),
bitnot1: (a) => bitNotU2(next(), a),
bitor: (a, b) => bitOrU2(next(), a, b),
rshift: (a, b) => rshiftU2(next(), a, b),
bitxor: (a, b) => bitXorU2(next(), a, b),
};
44 changes: 22 additions & 22 deletions packages/shader-ast-js/src/env/uvec3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,29 @@ import type { JSBuiltinsIntVec } from "../api.js";
import { POOL_UVEC3 } from "../pool.js";
import { VEC3 } from "./vec3.js";

const $ = POOL_UVEC3.next.bind(POOL_UVEC3);
const { next, uniform } = POOL_UVEC3;

export const UVEC3: JSBuiltinsIntVec = {
...VEC3(POOL_UVEC3),
add: (a, b) => addU3($(), a, b),
addvn: (a, b) => addNU3($(), a, b),
addnv: (a, b) => addNU3($(), b, a),
div: (a, b) => divU3($(), a, b),
divvn: (a, b) => divNU3($(), a, b),
divnv: (a, b) => divU3(null, [a, a, a], b),
modi: (a, b) => fmod3($(), a, b),
modivn: (a, b) => fmodN3($(), a, b),
modinv: (a, b) => fmod3(null, [a, a, a], b),
mul: (a, b) => mulU3($(), a, b),
mulvn: (a, b) => mulNU3($(), a, b),
mulnv: (a, b) => mulNU3($(), b, a),
sub: (a, b) => subU3($(), a, b),
subvn: (a, b) => subNU3($(), a, b),
subnv: (a, b) => subU3(null, [a, a, a], b),
bitand: (a, b) => bitAndU3($(), a, b),
lshift: (a, b) => lshiftU3($(), a, b),
bitnot1: (a) => bitNotU3($(), a),
bitor: (a, b) => bitOrU3($(), a, b),
rshift: (a, b) => rshiftU3($(), a, b),
bitxor: (a, b) => bitXorU3($(), a, b),
add: (a, b) => addU3(next(), a, b),
addvn: (a, b) => addNU3(next(), a, b),
addnv: (a, b) => addNU3(next(), b, a),
div: (a, b) => divU3(next(), a, b),
divvn: (a, b) => divNU3(next(), a, b),
divnv: (a, b) => divU3(null, uniform(a), b),
modi: (a, b) => fmod3(next(), a, b),
modivn: (a, b) => fmodN3(next(), a, b),
modinv: (a, b) => fmod3(null, uniform(a), b),
mul: (a, b) => mulU3(next(), a, b),
mulvn: (a, b) => mulNU3(next(), a, b),
mulnv: (a, b) => mulNU3(next(), b, a),
sub: (a, b) => subU3(next(), a, b),
subvn: (a, b) => subNU3(next(), a, b),
subnv: (a, b) => subU3(null, uniform(a), b),
bitand: (a, b) => bitAndU3(next(), a, b),
lshift: (a, b) => lshiftU3(next(), a, b),
bitnot1: (a) => bitNotU3(next(), a),
bitor: (a, b) => bitOrU3(next(), a, b),
rshift: (a, b) => rshiftU3(next(), a, b),
bitxor: (a, b) => bitXorU3(next(), a, b),
};
Loading

0 comments on commit 1c22d0c

Please sign in to comment.