Skip to content

Commit 6b889a6

Browse files
committed
explore: f32 by default
1 parent f935fbb commit 6b889a6

3 files changed

Lines changed: 15 additions & 4 deletions

File tree

packages/typegpu/src/data/numeric.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,16 @@ export const i32: I32 = Object.assign(i32Cast, {
125125
type: 'i32',
126126
}) as unknown as I32;
127127

128+
export type f32 = number;
129+
// export type f32 = number & {
130+
// __brand: 'f32';
131+
// [Symbol.operatorPlus](lhs: f32 | number, rhs: f32 | number): f32;
132+
// [Symbol.operatorMinus](lhs: f32 | number, rhs: f32 | number): f32;
133+
// [Symbol.operatorStar](lhs: f32 | number, rhs: f32 | number): f32;
134+
// [Symbol.operatorSlash](lhs: f32 | number, rhs: f32 | number): f32;
135+
// [Symbol.operatorPercent](lhs: f32 | number, rhs: f32 | number): f32;
136+
// };
137+
128138
const f32Cast = callableSchema({
129139
name: 'f32',
130140
schema: () => f32,

packages/typegpu/src/tgsl/generationHelpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export function concretize<T extends BaseData>(type: T): T | F32 | I32 {
5454
}
5555

5656
if (type.type === 'abstractInt') {
57-
return i32;
57+
return f32;
5858
}
5959

6060
return type;

packages/typegpu/src/tgsl/wgslGenerator.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,14 +1150,15 @@ ${this.ctx.pre}else ${alternate}`;
11501150
}
11511151
}
11521152

1153-
const snippet = this.blockVariable(varType, rawId, concretize(dataType), eq.origin);
1154-
const rhsSnippet = tryConvertSnippet(this.ctx, eq, dataType, false);
1153+
const concreteDataType = concretize(dataType);
1154+
const snippet = this.blockVariable(varType, rawId, concreteDataType, eq.origin);
1155+
const rhsSnippet = tryConvertSnippet(this.ctx, eq, concreteDataType, false);
11551156
const rhsStr = this.ctx.resolve(rhsSnippet.value, rhsSnippet.dataType).value;
11561157
return this.emitVarDecl(
11571158
this.ctx.pre,
11581159
varType,
11591160
snippet.value as string,
1160-
concretize(dataType),
1161+
concreteDataType,
11611162
rhsStr,
11621163
);
11631164
}

0 commit comments

Comments
 (0)