Skip to content
Merged
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
5 changes: 0 additions & 5 deletions packages/typegpu/src/data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
34 changes: 18 additions & 16 deletions packages/typegpu/src/data/numeric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
2 changes: 2 additions & 0 deletions packages/typegpu/src/data/wgslTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export interface matInfixNotation<T extends matBase> {
*/
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';
Expand All @@ -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';
Expand Down
6 changes: 2 additions & 4 deletions packages/typegpu/src/tgsl/conversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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') {
Expand Down
Loading