Skip to content
Draft
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
10 changes: 10 additions & 0 deletions packages/typegpu/src/data/numeric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,16 @@ export const i32: I32 = Object.assign(i32Cast, {
type: 'i32',
}) as unknown as I32;

export type f32 = number;
// export type f32 = number & {
// __brand: 'f32';
// [Symbol.operatorPlus](lhs: f32 | number, rhs: f32 | number): f32;
// [Symbol.operatorMinus](lhs: f32 | number, rhs: f32 | number): f32;
// [Symbol.operatorStar](lhs: f32 | number, rhs: f32 | number): f32;
// [Symbol.operatorSlash](lhs: f32 | number, rhs: f32 | number): f32;
// [Symbol.operatorPercent](lhs: f32 | number, rhs: f32 | number): f32;
// };

const f32Cast = callableSchema({
name: 'f32',
schema: () => f32,
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/src/tgsl/generationHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { UnknownData } from '../data/dataTypes.ts';
import { abstractFloat, abstractInt, bool, f32, i32 } from '../data/numeric.ts';

Check warning on line 2 in packages/typegpu/src/tgsl/generationHelpers.ts

View workflow job for this annotation

GitHub Actions / build-and-test

eslint(no-unused-vars)

Identifier 'i32' is imported but never used.
import { isRef } from '../data/ref.ts';
import {
isEphemeralSnippet,
Expand Down Expand Up @@ -54,7 +54,7 @@
}

if (type.type === 'abstractInt') {
return i32;
return f32;
}

return type;
Expand Down
7 changes: 4 additions & 3 deletions packages/typegpu/src/tgsl/wgslGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1150,14 +1150,15 @@ ${this.ctx.pre}else ${alternate}`;
}
}

const snippet = this.blockVariable(varType, rawId, concretize(dataType), eq.origin);
const rhsSnippet = tryConvertSnippet(this.ctx, eq, dataType, false);
const concreteDataType = concretize(dataType);
const snippet = this.blockVariable(varType, rawId, concreteDataType, eq.origin);
const rhsSnippet = tryConvertSnippet(this.ctx, eq, concreteDataType, false);
const rhsStr = this.ctx.resolve(rhsSnippet.value, rhsSnippet.dataType).value;
return this.emitVarDecl(
this.ctx.pre,
varType,
snippet.value as string,
concretize(dataType),
concreteDataType,
rhsStr,
);
}
Expand Down
Loading