Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ const initKernel = tgpu.computeFn({
return;
}

randf.seed3(d.vec3f(d.f32(idx & 0xffff), d.f32(idx >> 16), initSeed.$));
randf.seed3(d.vec3f(d.f32(idx & 0xffff), d.f32(idx >>> 16), initSeed.$));
const n = randf.sample();
initLayout.$.data[idx] = d.u32(std.floor(n * 256.0));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ const finalizeReductionPipeline = root.createGuardedComputePipeline(() => {
'use gpu';
const packed = std.atomicLoad(reductionLayout.$.packed);
reductionLayout.$.bestIdx = packed & 0xffff;
reductionLayout.$.bestFitness = (d.f32(packed >> 16) / 65535) * 64;
reductionLayout.$.bestFitness = (d.f32(packed >>> 16) / 65535) * 64;
});

const colors = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ const mainFragment = tgpu.fragmentFn({
}
return vec4f(
color,
select(f32(0), f32(1), (u32(screenPosition.x) >> 3) % 2 !== (u32(screenPosition.y) >> 3) % 2),
select(f32(0), f32(1), (u32(screenPosition.x) >>> 3) % 2 !== (u32(screenPosition.y) >>> 3) % 2),
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const characterFn = tgpu.fn(
// Convert 2D bitmap position to 1D bit index (row-major order)
const a = d.u32(pos.x + 5 * pos.y);
// Extract the bit at position 'a' from the character bitmap 'n'
return d.f32((n >> a) & 1);
return d.f32((n >>> a) & 1);
});

const video = document.querySelector('video') as HTMLVideoElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const videoPreprocessKernel = tgpu.computeFn({
return;
}

const coord = d.vec2u(i & MODEL_COORD_MASK, std.bitShiftRight(i, MODEL_COORD_SHIFT));
const coord = d.vec2u(i & MODEL_COORD_MASK, i >>> MODEL_COORD_SHIFT);
const pixel = d.vec2f(coord) + 0.5;
const cropUv = d.vec2f(MODEL_SIZE.x - pixel.x, pixel.y) / MODEL_SIZE;
const sourceUv =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const upsampleMaskLayout = tgpu.bindGroupLayout({

const maskCoord = (i: number) => {
'use gpu';
return d.vec2u(i & MODEL_COORD_MASK, std.bitShiftRight(i, MODEL_COORD_SHIFT));
return d.vec2u(i & MODEL_COORD_MASK, i >>> MODEL_COORD_SHIFT);
};

const maskIndex = (coord: d.v2i) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ const cascadePassPipeline = root
}

if (layer + 1 < cascadeAmountUniform.$ && T > 0.01) {
const probesU = d.vec2u(std.max(probes.x >> 1, 1), std.max(probes.y >> 1, 1));
const probesU = d.vec2u(std.max(probes.x >>> 1, 1), std.max(probes.y >>> 1, 1));
const tileOrigin = d.vec2f(dirActual) * d.vec2f(probesU);
const probePixel = std.clamp(
probePos * d.vec2f(probesU),
Expand Down Expand Up @@ -254,7 +254,7 @@ const overlayFrag = tgpu.fragmentFn({
const debugLayer = overlayDebugCascadeUniform.$;
const cascadeProbes = cascadeProbesUniform.$;
const probes = std.max(
d.vec2u(cascadeProbes.x >> debugLayer, cascadeProbes.y >> debugLayer),
d.vec2u(cascadeProbes.x >>> debugLayer, cascadeProbes.y >>> debugLayer),
d.vec2u(1),
);
const raysDimStored = d.u32(2) << debugLayer;
Expand Down Expand Up @@ -304,7 +304,7 @@ const overlayFrag = tgpu.fragmentFn({
const rayDist = sdf.sdLine(uv, probePos, probePos + rayDir * std.max(rayEndDistance, 0.01));

if (rayDist < minRayDist) {
const dirStored = d.vec2u((ri % raysDimActual) >> 1, d.u32(ri / raysDimActual) >> 1);
const dirStored = d.vec2u((ri % raysDimActual) >>> 1, d.u32(ri / raysDimActual) >>> 1);
const sample = std.textureLoad(
overlayDebugBGL.$.cascadeTex,
d.vec2i(dirStored * probes + probe),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ const sampleBitpacked = (sampleUv: d.v2f, gs: number): number => {
const packedX = cellX / 32;
const bitIndex = cellX % 32;
const packed = std.textureLoad(displayLayout.$.source, d.vec2u(packedX, cellY)).x;
return (packed >> bitIndex) & d.u32(1);
return (packed >>> bitIndex) & d.u32(1);
};

const cellSamplerSlot = tgpu.slot<(uv: d.v2f, gs: number) => number>(sampleRegular);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ const gatherNeighborhood = (

const shiftLeft = (center: number, left: number): number => {
'use gpu';
return (center << 1) | (left >> 31);
return (center << 1) | (left >>> 31);
};

const shiftRight = (center: number, right: number): number => {
'use gpu';
return (center >> 1) | (right << 31);
return (center >>> 1) | (right << 31);
};

const bitpackedNeighbors = (n: d.Infer<typeof Neighborhood3x3>): d.Infer<typeof Neighbors8> => {
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin/src/rules/noUnsupportedSyntax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,6 @@ export const noUnsupportedSyntax = createRule({
}),
});

const unsupportedAssignmentOps = ['&&=', '**=', '||=', '>>>=', '??='];
const unsupportedBinaryOps = ['==', '!=', '>>>', 'in', 'instanceof', '|>'];
const unsupportedAssignmentOps = ['&&=', '**=', '||=', '??='];
const unsupportedBinaryOps = ['==', '!=', 'in', 'instanceof', '|>'];
const unsupportedUnaryOps = ['+', 'typeof', 'void', 'delete'];
12 changes: 2 additions & 10 deletions packages/eslint-plugin/tests/rules/noUnsupportedSyntax.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('noUnsupportedSyntax', () => {
],
},
{
code: "const fn = () => { 'use gpu'; let a = 0; a **= 1; a ??= 1; a &&= 1; a ||= 1; a >>>= 1; }",
code: "const fn = () => { 'use gpu'; let a = 0; a **= 1; a ??= 1; a &&= 1; a ||= 1; }",
errors: [
{
messageId: 'unexpected',
Expand All @@ -39,10 +39,6 @@ describe('noUnsupportedSyntax', () => {
messageId: 'unexpected',
data: { snippet: 'a ||= 1', syntax: "assignment expression '||='" },
},
{
messageId: 'unexpected',
data: { snippet: 'a >>>= 1', syntax: "assignment expression '>>>='" },
},
],
},
{
Expand Down Expand Up @@ -91,12 +87,8 @@ describe('noUnsupportedSyntax', () => {
],
},
{
code: "const fn = () => { 'use gpu'; a >>> b; c in d; e instanceof Foo; return g != 0; }",
code: "const fn = () => { 'use gpu'; c in d; e instanceof Foo; return g != 0; }",
errors: [
{
messageId: 'unexpected',
data: { snippet: 'a >>> b', syntax: "binary operator '>>>'" },
},
{
messageId: 'unexpected',
data: { snippet: 'c in d', syntax: "binary operator 'in'" },
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu-geometry/src/lines/lineVariableWidth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const lineVariableWidth = tgpu.fn(
}

const coreVertexIndex = (vertexIndex - 2) & 0b11;
const joinVertexIndex = (vertexIndex - 2) >> 2;
const joinVertexIndex = (vertexIndex - 2) >>> 2;
let join = JoinInput();

const normAB = normalize(AB);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const polylineVariableWidth = tgpu.fn(
}

const coreVertexIndex = (vertexIndex - 2) & 0b11;
const joinVertexIndex = (vertexIndex - 2) >> 2;
const joinVertexIndex = (vertexIndex - 2) >>> 2;
let join = JoinInput();
let isCap = false;
let shouldJoin = false;
Expand Down
11 changes: 5 additions & 6 deletions packages/typegpu-noise/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ export const rotl = tgpu.fn(
[d.u32, d.u32],
d.u32,
)((x, k) => {
// TODO(#2768) - remove the conditional expression below
return std.isBeingTranspiled() ? (x << k) | (x >> (32 - k)) : (x << k) | (x >>> (32 - k));
return (x << k) | (x >>> (32 - k));
});

/**
Expand Down Expand Up @@ -65,13 +64,13 @@ export const hash = tgpu.fn(
d.u32,
)((value) => {
if (std.isBeingTranspiled()) {
let x = value ^ (value >> 17);
let x = value ^ (value >>> 17);
x *= d.u32(0xed5ad4bb);
x ^= x >> 11;
x ^= x >>> 11;
x *= d.u32(0xac4c1b51);
x ^= x >> 15;
x ^= x >>> 15;
x *= d.u32(0x31848bab);
x ^= x >> 14;
x ^= x >>> 14;
return x;
} else {
let x = value ^ (value >>> 17);
Expand Down
10 changes: 5 additions & 5 deletions packages/typegpu-radiance-cascades/src/cascades.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export const cascadePassCompute = tgpu.computeFn({
const params = cascadePassBGL.$.staticParams;
const layer = cascadePassBGL.$.layer;
const probes = std.max(
d.vec2u(params.baseProbes.x >> layer, params.baseProbes.y >> layer),
d.vec2u(params.baseProbes.x >>> layer, params.baseProbes.y >>> layer),
d.vec2u(1, 1),
);

Expand Down Expand Up @@ -144,8 +144,8 @@ export const cascadePassCompute = tgpu.computeFn({

let accum = d.vec4f();

for (let i = 0; i < 4; i++) {
const dirActual = dirStored * 2 + d.vec2u(i & 1, i >> 1);
for (let i = d.u32(0); i < 4; i++) {
const dirActual = dirStored * 2 + d.vec2u(i & 1, i >>> 1);
const rayIndex = d.f32(dirActual.y * raysDimActual + dirActual.x) + 0.5;
const angle = (rayIndex / rayCountActual) * (Math.PI * 2) - Math.PI;
const cosA = std.cos(angle);
Expand All @@ -162,7 +162,7 @@ export const cascadePassCompute = tgpu.computeFn({
let T = d.f32(marchResult.transmittance);

if (layer < params.cascadeCount - 1 && T > 0.01) {
const probesU = std.max(d.vec2u(probes.x >> 1, probes.y >> 1), d.vec2u(1));
const probesU = std.max(d.vec2u(probes.x >>> 1, probes.y >>> 1), d.vec2u(1));
const tileOrigin = d.vec2f(dirActual) * d.vec2f(probesU);
const probePixel = std.clamp(
probePos * d.vec2f(probesU),
Expand Down Expand Up @@ -226,7 +226,7 @@ export const buildRadianceFieldCompute = tgpu.computeFn({

let sum = d.vec3f();
for (let i = d.u32(0); i < 4; i++) {
const offset = d.vec2f(i & 1, i >> 1) * uvStride;
const offset = d.vec2f(i & 1, i >>> 1) * uvStride;
const sample = std.textureSampleLevel(
buildRadianceFieldBGL.$.src,
buildRadianceFieldBGL.$.srcSampler,
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu-sort/src/bitonic/bitonicSort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const bitonicStepKernel = tgpu.computeFn({

const maskBelow = stride - 1;
const below = tid & maskBelow;
const above = tid >> shift;
const above = tid >>> shift;

const i = below + above * (stride << 1);
const ixj = i + stride;
Expand Down
6 changes: 3 additions & 3 deletions packages/typegpu/src/data/vectorOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1116,13 +1116,13 @@ export const VectorOps = {

bitShiftRight: {
vec2i: binaryComponentWise2i2u((a, b) => a >> b),
vec2u: binaryComponentWise2u((a, b) => a >> b),
vec2u: binaryComponentWise2u((a, b) => a >>> b),

vec3i: binaryComponentWise3i3u((a, b) => a >> b),
vec3u: binaryComponentWise3u((a, b) => a >> b),
vec3u: binaryComponentWise3u((a, b) => a >>> b),

vec4i: binaryComponentWise4i4u((a, b) => a >> b),
vec4u: binaryComponentWise4u((a, b) => a >> b),
vec4u: binaryComponentWise4u((a, b) => a >>> b),
} as Record<
VecKind,
<T extends wgsl.AnyIntegerVecInstance, U extends wgsl.AnyUnsignedVecInstance>(a: T, b: U) => T
Expand Down
12 changes: 12 additions & 0 deletions packages/typegpu/src/data/wgslTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1598,6 +1598,18 @@ export function isMat(value: unknown): value is Mat2x2f | Mat3x3f | Mat4x4f {
return isMat2x2f(value) || isMat3x3f(value) || isMat4x4f(value);
}

export function isInteger(value: unknown): value is AbstractInt | I32 | U32 {
return (
isMarkedInternal(value) && ['abstractInt', 'i32', 'u32'].includes((value as AnyWgslData)?.type)
);
}

export function isIntegerVec(
value: unknown,
): value is Vec2i | Vec3i | Vec4i | Vec2u | Vec3u | Vec4u {
return isVec(value) && isInteger(value.primitive);
}

export function isFloat32VecInstance(element: unknown): element is AnyFloat32VecInstance {
return isVecInstance(element) && ['vec2f', 'vec3f', 'vec4f'].includes(element.kind);
}
Expand Down
Loading
Loading