diff --git a/packages/typegpu/src/data/index.ts b/packages/typegpu/src/data/index.ts index 9aeb7edc16..5eebe77415 100644 --- a/packages/typegpu/src/data/index.ts +++ b/packages/typegpu/src/data/index.ts @@ -48,11 +48,6 @@ assignInfixOperator(MatBase, 'mul', Operator.star); }; } -// TODO: Remove this side-effect once we have shaderbits -import { f32 } from './numeric.ts'; -// oxlint-disable-next-line typescript/no-explicit-any -(globalThis as any).__TYPEGPU_F32__ = f32; - export { bool, f16, f32, i32, u16, u32 } from './numeric.ts'; export { isAlignAttrib, diff --git a/packages/typegpu/src/data/numeric.ts b/packages/typegpu/src/data/numeric.ts index d49368843b..85fbc2bb4e 100644 --- a/packages/typegpu/src/data/numeric.ts +++ b/packages/typegpu/src/data/numeric.ts @@ -2,22 +2,6 @@ import { $internal } from '../shared/symbols.ts'; import type { AbstractFloat, AbstractInt, Bool, F16, F32, I32, U16, U32 } from './wgslTypes.ts'; import { callableSchema } from '../core/function/createCallableSchema.ts'; -export const abstractInt = { - [$internal]: {}, - type: 'abstractInt', - toString() { - return 'abstractInt'; - }, -} as AbstractInt; - -export const abstractFloat = { - [$internal]: {}, - type: 'abstractFloat', - toString() { - return 'abstractFloat'; - }, -} as AbstractFloat; - const boolCast = callableSchema({ name: 'bool', schema: () => bool, @@ -299,3 +283,21 @@ export const f16: F16 = Object.assign(f16Cast, { [$internal]: {}, type: 'f16', }) as unknown as F16; + +export const abstractInt = { + [$internal]: {}, + type: 'abstractInt', + toString() { + return 'abstractInt'; + }, + concretized: i32, +} as AbstractInt; + +export const abstractFloat = { + [$internal]: {}, + type: 'abstractFloat', + toString() { + return 'abstractFloat'; + }, + concretized: f32, +} as AbstractFloat; diff --git a/packages/typegpu/src/data/wgslTypes.ts b/packages/typegpu/src/data/wgslTypes.ts index dc85031925..f8757d90b5 100644 --- a/packages/typegpu/src/data/wgslTypes.ts +++ b/packages/typegpu/src/data/wgslTypes.ts @@ -129,6 +129,7 @@ export interface matInfixNotation { */ export interface AbstractInt extends BaseData { readonly type: 'abstractInt'; + readonly concretized: I32; // Type-tokens, not available at runtime readonly [$repr]: number; readonly [$invalidSchemaReason]: 'Abstract numerics are not host-shareable'; @@ -140,6 +141,7 @@ export interface AbstractInt extends BaseData { */ export interface AbstractFloat extends BaseData { readonly type: 'abstractFloat'; + readonly concretized: F32; // Type-tokens, not available at runtime readonly [$repr]: number; readonly [$invalidSchemaReason]: 'Abstract numerics are not host-shareable'; diff --git a/packages/typegpu/src/tgsl/conversion.ts b/packages/typegpu/src/tgsl/conversion.ts index 7c83aec720..f410e53e6d 100644 --- a/packages/typegpu/src/tgsl/conversion.ts +++ b/packages/typegpu/src/tgsl/conversion.ts @@ -5,6 +5,7 @@ import { derefSnippet, RefOperator } from '../data/ref.ts'; import { schemaCallWrapperGPU } from '../data/schemaCallWrapper.ts'; import { snip, type Snippet } from '../data/snippet.ts'; import { + type AbstractFloat, type AnyWgslData, type BaseData, type F16, @@ -123,10 +124,7 @@ function getImplicitConversionRank(src: BaseData, dest: BaseData): ConversionRan if ((trueSrc.type === 'u32' || trueSrc.type === 'i32') && trueDst.type === 'abstractFloat') { // When one of the types is a float (abstract or not), we don't want to cast it to a non-float type, // which would cause it to lose precision. We instead choose the common type to be f32. - - // TODO: Remove this side-effect once we have shaderbits - // oxlint-disable-next-line typescript/no-explicit-any - return { rank: 1, action: 'cast', targetType: (globalThis as any).__TYPEGPU_F32__ }; + return { rank: 1, action: 'cast', targetType: (trueDst as AbstractFloat).concretized }; } if (trueSrc.type === 'abstractFloat') {