Skip to content

Commit 2dfe4f4

Browse files
impr: Remove globalThis assignment (#2403)
1 parent b538979 commit 2dfe4f4

4 files changed

Lines changed: 22 additions & 25 deletions

File tree

packages/typegpu/src/data/index.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,6 @@ assignInfixOperator(MatBase, 'mul', Operator.star);
4848
};
4949
}
5050

51-
// TODO: Remove this side-effect once we have shaderbits
52-
import { f32 } from './numeric.ts';
53-
// oxlint-disable-next-line typescript/no-explicit-any
54-
(globalThis as any).__TYPEGPU_F32__ = f32;
55-
5651
export { bool, f16, f32, i32, u16, u32 } from './numeric.ts';
5752
export {
5853
isAlignAttrib,

packages/typegpu/src/data/numeric.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,6 @@ import { $internal } from '../shared/symbols.ts';
22
import type { AbstractFloat, AbstractInt, Bool, F16, F32, I32, U16, U32 } from './wgslTypes.ts';
33
import { callableSchema } from '../core/function/createCallableSchema.ts';
44

5-
export const abstractInt = {
6-
[$internal]: {},
7-
type: 'abstractInt',
8-
toString() {
9-
return 'abstractInt';
10-
},
11-
} as AbstractInt;
12-
13-
export const abstractFloat = {
14-
[$internal]: {},
15-
type: 'abstractFloat',
16-
toString() {
17-
return 'abstractFloat';
18-
},
19-
} as AbstractFloat;
20-
215
const boolCast = callableSchema({
226
name: 'bool',
237
schema: () => bool,
@@ -299,3 +283,21 @@ export const f16: F16 = Object.assign(f16Cast, {
299283
[$internal]: {},
300284
type: 'f16',
301285
}) as unknown as F16;
286+
287+
export const abstractInt = {
288+
[$internal]: {},
289+
type: 'abstractInt',
290+
toString() {
291+
return 'abstractInt';
292+
},
293+
concretized: i32,
294+
} as AbstractInt;
295+
296+
export const abstractFloat = {
297+
[$internal]: {},
298+
type: 'abstractFloat',
299+
toString() {
300+
return 'abstractFloat';
301+
},
302+
concretized: f32,
303+
} as AbstractFloat;

packages/typegpu/src/data/wgslTypes.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ export interface matInfixNotation<T extends matBase> {
129129
*/
130130
export interface AbstractInt extends BaseData {
131131
readonly type: 'abstractInt';
132+
readonly concretized: I32;
132133
// Type-tokens, not available at runtime
133134
readonly [$repr]: number;
134135
readonly [$invalidSchemaReason]: 'Abstract numerics are not host-shareable';
@@ -140,6 +141,7 @@ export interface AbstractInt extends BaseData {
140141
*/
141142
export interface AbstractFloat extends BaseData {
142143
readonly type: 'abstractFloat';
144+
readonly concretized: F32;
143145
// Type-tokens, not available at runtime
144146
readonly [$repr]: number;
145147
readonly [$invalidSchemaReason]: 'Abstract numerics are not host-shareable';

packages/typegpu/src/tgsl/conversion.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { derefSnippet, RefOperator } from '../data/ref.ts';
55
import { schemaCallWrapperGPU } from '../data/schemaCallWrapper.ts';
66
import { snip, type Snippet } from '../data/snippet.ts';
77
import {
8+
type AbstractFloat,
89
type AnyWgslData,
910
type BaseData,
1011
type F16,
@@ -123,10 +124,7 @@ function getImplicitConversionRank(src: BaseData, dest: BaseData): ConversionRan
123124
if ((trueSrc.type === 'u32' || trueSrc.type === 'i32') && trueDst.type === 'abstractFloat') {
124125
// When one of the types is a float (abstract or not), we don't want to cast it to a non-float type,
125126
// which would cause it to lose precision. We instead choose the common type to be f32.
126-
127-
// TODO: Remove this side-effect once we have shaderbits
128-
// oxlint-disable-next-line typescript/no-explicit-any
129-
return { rank: 1, action: 'cast', targetType: (globalThis as any).__TYPEGPU_F32__ };
127+
return { rank: 1, action: 'cast', targetType: (trueDst as AbstractFloat).concretized };
130128
}
131129

132130
if (trueSrc.type === 'abstractFloat') {

0 commit comments

Comments
 (0)