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
3 changes: 3 additions & 0 deletions packages/typegpu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
},
"type": "module",
"sideEffects": false,
"imports": {
"#shaderbit": "./src/shaderbit/index.ts"
},
"exports": {
"./package.json": "./package.json",
".": {
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/src/core/buffer/bufferShorthand.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ResolvedSnippet } from '../../data/snippet.ts';
import type { ResolvedSnippet } from '../../tgsl/snippet.ts';
import type { BaseData } from '../../data/wgslTypes.ts';
import type { StorageFlag } from '../../extension.ts';
import { getName, setName, type TgpuNamable } from '../../shared/meta.ts';
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/src/core/buffer/bufferUsage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { schemaCallWrapper } from '../../data/schemaCallWrapper.ts';
import { type ResolvedSnippet, snip } from '../../data/snippet.ts';
import { type ResolvedSnippet, snip } from '../../tgsl/snippet.ts';
import { type AnyWgslData, type BaseData, isNaturallyEphemeral } from '../../data/wgslTypes.ts';
import { IllegalBufferAccessError } from '../../errors.ts';
import { getExecMode, inCodegenMode, isInsideTgpuFn } from '../../execMode.ts';
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/src/core/constant/tgpuConstant.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isData, type AnyData } from '../../data/dataTypes.ts';
import { type ResolvedSnippet, snip } from '../../data/snippet.ts';
import { type ResolvedSnippet, snip } from '../../tgsl/snippet.ts';
import {
type AnyWgslData,
type BaseData,
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/src/core/declare/tgpuDeclare.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type ResolvedSnippet, snip } from '../../data/snippet.ts';
import { type ResolvedSnippet, snip } from '../../tgsl/snippet.ts';
import { Void } from '../../data/wgslTypes.ts';
import { $internal, $resolve } from '../../shared/symbols.ts';
import type { ResolutionCtx, SelfResolvable } from '../../types.ts';
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/src/core/function/autoIO.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { builtin, type OmitBuiltins } from '../../builtin.ts';
import { AutoStruct } from '../../data/autoStruct.ts';
import type { ResolvedSnippet } from '../../data/snippet.ts';
import type { ResolvedSnippet } from '../../tgsl/snippet.ts';
import { vec4f } from '../../data/vector.ts';
import type { FormatToWGSLType } from '../../data/vertexFormatData.ts';
import type { BaseData, v4f } from '../../data/wgslTypes.ts';
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/src/core/function/createCallableSchema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type MapValueToSnippet, type ResolvedSnippet, snip } from '../../data/snippet.ts';
import { type MapValueToSnippet, type ResolvedSnippet, snip } from '../../tgsl/snippet.ts';
import { type BaseData, isPtr } from '../../data/wgslTypes.ts';
import { setName } from '../../shared/meta.ts';
import { $gpuCallable } from '../../shared/symbols.ts';
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/src/core/function/dualImpl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type MapValueToSnippet, snip } from '../../data/snippet.ts';
import { type MapValueToSnippet, snip } from '../../tgsl/snippet.ts';
import { setName } from '../../shared/meta.ts';
import { $gpuCallable } from '../../shared/symbols.ts';
import { tryConvertSnippet } from '../../tgsl/conversion.ts';
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/src/core/function/entryInputRouter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { undecorate } from '../../data/dataTypes.ts';
import { snip, type Snippet } from '../../data/snippet.ts';
import { snip, type Snippet } from '../../tgsl/snippet.ts';
import { $internal, $repr } from '../../shared/symbols.ts';
import { type BaseData, isWgslStruct } from '../../data/wgslTypes.ts';

Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/src/core/function/fnCore.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getAttributesString } from '../../data/attributes.ts';
import { undecorate } from '../../data/dataTypes.ts';
import { type ResolvedSnippet, snip } from '../../data/snippet.ts';
import { type ResolvedSnippet, snip } from '../../tgsl/snippet.ts';
import { type BaseData, isWgslData, isWgslStruct, Void } from '../../data/wgslTypes.ts';
import { MissingLinksError } from '../../errors.ts';
import { getMetaData, getName } from '../../shared/meta.ts';
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/src/core/function/shelllessImpl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ResolvedSnippet } from '../../data/snippet.ts';
import type { ResolvedSnippet } from '../../tgsl/snippet.ts';
import type { BaseData } from '../../data/wgslTypes.ts';
import { getName } from '../../shared/meta.ts';
import { $getNameForward, $internal, $resolve } from '../../shared/symbols.ts';
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/src/core/function/tgpuComputeFn.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { AnyComputeBuiltin } from '../../builtin.ts';
import type { ResolvedSnippet } from '../../data/snippet.ts';
import type { ResolvedSnippet } from '../../tgsl/snippet.ts';
import { Void } from '../../data/wgslTypes.ts';
import { getName, setName, type TgpuNamable } from '../../shared/meta.ts';
import { $getNameForward, $internal, $resolve } from '../../shared/symbols.ts';
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/src/core/function/tgpuFn.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ResolvedSnippet } from '../../data/snippet.ts';
import type { ResolvedSnippet } from '../../tgsl/snippet.ts';
import { schemaCallWrapper } from '../../data/schemaCallWrapper.ts';
import { type BaseData, Void } from '../../data/wgslTypes.ts';
import { ExecutionError } from '../../errors.ts';
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/src/core/function/tgpuFragmentFn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
} from '../../builtin.ts';
import type { UndecorateRecord } from '../../data/dataTypes.ts';
import type { InstanceToSchema } from '../../data/instanceToSchema.ts';
import type { ResolvedSnippet } from '../../data/snippet.ts';
import type { ResolvedSnippet } from '../../tgsl/snippet.ts';
import type {
BaseData,
Decorated,
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/src/core/function/tgpuVertexFn.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { AnyVertexInputBuiltin, AnyVertexOutputBuiltin, OmitBuiltins } from '../../builtin.ts';
import type { UndecorateRecord } from '../../data/dataTypes.ts';
import type { ResolvedSnippet } from '../../data/snippet.ts';
import type { ResolvedSnippet } from '../../tgsl/snippet.ts';
import type { BaseData, Decorated, Interpolate, Location } from '../../data/wgslTypes.ts';
import { getName, setName, type TgpuNamable } from '../../shared/meta.ts';
import { $getNameForward, $internal, $resolve } from '../../shared/symbols.ts';
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/src/core/pipeline/computePipeline.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { AnyComputeBuiltin } from '../../builtin.ts';
import type { TgpuQuerySet } from '../../core/querySet/querySet.ts';
import { type ResolvedSnippet, snip } from '../../data/snippet.ts';
import { type ResolvedSnippet, snip } from '../../tgsl/snippet.ts';
import type { AnyWgslData } from '../../data/wgslTypes.ts';
import { Void } from '../../data/wgslTypes.ts';
import { applyBindGroups } from './applyPipelineState.ts';
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/src/core/pipeline/renderPipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { TgpuQuerySet } from '../../core/querySet/querySet.ts';
import { isBuiltin } from '../../data/attributes.ts';
import { type Disarray, getCustomLocation, type UndecorateRecord } from '../../data/dataTypes.ts';
import { sizeOf } from '../../data/sizeOf.ts';
import { type ResolvedSnippet, snip } from '../../data/snippet.ts';
import { type ResolvedSnippet, snip } from '../../tgsl/snippet.ts';
import type {
WgslTexture,
WgslTextureDepth2d,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { AnyData } from '../../data/dataTypes.ts';
import { type Origin, type ResolvedSnippet, snip } from '../../data/snippet.ts';
import { type Origin, type ResolvedSnippet, snip } from '../../tgsl/snippet.ts';
import type { BaseData } from '../../data/wgslTypes.ts';
import { inCodegenMode } from '../../execMode.ts';
import type { InferGPU } from '../../shared/repr.ts';
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/src/core/resolve/namespace.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ResolvedSnippet } from '../../data/snippet.ts';
import type { ResolvedSnippet } from '../../tgsl/snippet.ts';
import { type NameRegistry, RandomNameRegistry, StrictNameRegistry } from '../../nameRegistry.ts';
import { getName } from '../../shared/meta.ts';
import { $internal } from '../../shared/symbols.ts';
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/src/core/resolve/stitch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isSnippet, type Snippet } from '../../data/snippet.ts';
import { isSnippet, type Snippet } from '../../tgsl/snippet.ts';
import { getResolutionCtx } from '../../execMode.ts';
import type { ResolutionCtx } from '../../types.ts';

Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/src/core/resolve/tgpuResolve.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type ResolvedSnippet, snip } from '../../data/snippet.ts';
import { type ResolvedSnippet, snip } from '../../tgsl/snippet.ts';
import { Void } from '../../data/wgslTypes.ts';
import { type ResolutionResult, resolve as resolveImpl } from '../../resolutionCtx.ts';
import { $internal, $resolve } from '../../shared/symbols.ts';
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/src/core/sampler/sampler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { WgslComparisonSamplerProps, WgslSamplerProps } from '../../data/sampler.ts';
import { type ResolvedSnippet, snip } from '../../data/snippet.ts';
import { type ResolvedSnippet, snip } from '../../tgsl/snippet.ts';
import type { TgpuNamable } from '../../shared/meta.ts';
import { getName, setName } from '../../shared/meta.ts';
import type { Infer } from '../../shared/repr.ts';
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/src/core/slot/accessor.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type AnyData, isData } from '../../data/dataTypes.ts';
import { schemaCallWrapper } from '../../data/schemaCallWrapper.ts';
import { isSnippet, type ResolvedSnippet, snip } from '../../data/snippet.ts';
import { isSnippet, type ResolvedSnippet, snip } from '../../tgsl/snippet.ts';
import type { BaseData } from '../../data/wgslTypes.ts';
import { getResolutionCtx, inCodegenMode } from '../../execMode.ts';
import { getName, hasTinyestMetadata, setName } from '../../shared/meta.ts';
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/src/core/texture/externalTexture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { textureExternal, type WgslExternalTexture } from '../../data/texture.ts
import { valueProxyHandler } from '../valueProxyUtils.ts';
import { inCodegenMode } from '../../execMode.ts';
import type { ResolutionCtx, SelfResolvable } from '../../types.ts';
import { type ResolvedSnippet, snip } from '../../data/snippet.ts';
import { type ResolvedSnippet, snip } from '../../tgsl/snippet.ts';
import type { Infer } from '../../shared/repr.ts';

// ----------
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/src/core/texture/texture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
type WgslTextureProps,
} from '../../data/texture.ts';
import { inCodegenMode } from '../../execMode.ts';
import { type ResolvedSnippet, snip } from '../../data/snippet.ts';
import { type ResolvedSnippet, snip } from '../../tgsl/snippet.ts';
import type { F32, Vec4f, Vec4i, Vec4u } from '../../data/wgslTypes.ts';
import type { TgpuNamable } from '../../shared/meta.ts';
import { getName, setName } from '../../shared/meta.ts';
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/src/core/unroll/tgpuUnroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { stitch } from '../resolve/stitch.ts';
import { $gpuCallable, $internal, $resolve } from '../../../src/shared/symbols.ts';
import { setName } from '../../../src/shared/meta.ts';
import type { DualFn } from '../../../src/types.ts';
import { type ResolvedSnippet, snip, type Snippet } from '../../../src/data/snippet.ts';
import { type ResolvedSnippet, snip, type Snippet } from '../../tgsl/snippet.ts';
import type { ResolutionCtx, SelfResolvable } from '../../../src/types.ts';
import type { BaseData } from '../../data/wgslTypes.ts';

Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/src/core/valueProxyUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Snippet } from '../data/snippet.ts';
import type { Snippet } from '../tgsl/snippet.ts';
import { getGPUValue } from '../getGPUValue.ts';
import { $internal, $ownSnippet, $resolve } from '../shared/symbols.ts';
import { accessIndex } from '../tgsl/accessIndex.ts';
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/src/core/variable/tgpuVariable.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { AnyData } from '../../data/dataTypes.ts';
import { type ResolvedSnippet, snip } from '../../data/snippet.ts';
import { type ResolvedSnippet, snip } from '../../tgsl/snippet.ts';
import { type BaseData, isNaturallyEphemeral } from '../../data/wgslTypes.ts';
import { IllegalVarAccessError } from '../../errors.ts';
import { getExecMode, isInsideTgpuFn } from '../../execMode.ts';
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/src/data/autoStruct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { isValidProp } from '../nameRegistry.ts';
import { getName, setName } from '../shared/meta.ts';
import { $internal, $repr, $resolve } from '../shared/symbols.ts';
import type { ResolutionCtx, SelfResolvable } from '../types.ts';
import type { ResolvedSnippet } from './snippet.ts';
import type { ResolvedSnippet } from '../tgsl/snippet.ts';
import type { BaseData, WgslStruct } from './wgslTypes.ts';

/**
Expand Down
12 changes: 1 addition & 11 deletions packages/typegpu/src/data/dataTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { $internal } from '../shared/symbols.ts';
import type { Prettify } from '../shared/utilityTypes.ts';
import { vertexFormats } from '../shared/vertexFormat.ts';
import type { WgslExternalTexture, WgslStorageTexture, WgslTexture } from './texture.ts';
import type { Snippet } from './snippet.ts';
import type { Snippet } from '../tgsl/snippet.ts';
import type { PackedData } from './vertexFormatData.ts';
import * as wgsl from './wgslTypes.ts';
import type { WgslComparisonSampler, WgslSampler } from './sampler.ts';
Expand Down Expand Up @@ -145,13 +145,6 @@ export function undecorate(data: BaseData): BaseData {
return data;
}

export function unptr(data: BaseData | UnknownData): BaseData | UnknownData {
if (wgsl.isPtr(data)) {
return data.inner;
}
return data;
}

const looseTypeLiterals = ['unstruct', 'disarray', 'loose-decorated', ...vertexFormats] as const;

export type LooseTypeLiteral = (typeof looseTypeLiterals)[number];
Expand Down Expand Up @@ -233,9 +226,6 @@ export type AnyConcreteData = Exclude<
| WgslComparisonSampler
>;

export const UnknownData = Symbol('UNKNOWN');
export type UnknownData = typeof UnknownData;

export class InfixDispatch {
readonly name: string;
readonly lhs: Snippet;
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/src/data/matrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { $internal, $resolve } from '../shared/symbols.ts';
import { numericLiteralToSnippet } from '../tgsl/generationHelpers.ts';
import type { ResolutionCtx, SelfResolvable } from '../types.ts';
import { f32 } from './numeric.ts';
import { type ResolvedSnippet } from './snippet.ts';
import { type ResolvedSnippet } from '../tgsl/snippet.ts';
import { vec2f, vec3f, vec4f } from './vector.ts';
import {
type BaseData,
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/src/data/ptr.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { $internal } from '../shared/symbols.ts';
import { type Origin, type OriginToPtrParams, originToPtrParams } from './snippet.ts';
import { type Origin, type OriginToPtrParams, originToPtrParams } from '../tgsl/snippet.ts';
import type { Access, AddressSpace, BaseData, Ptr, StorableData } from './wgslTypes.ts';

export function ptrFn<T extends StorableData>(inner: T): Ptr<'function', T, 'read-write'> {
Expand Down
12 changes: 6 additions & 6 deletions packages/typegpu/src/data/ref.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { stitch } from '../core/resolve/stitch.ts';
import { WgslTypeError } from '../errors.ts';
import { isPtrType, type PtrBit } from '../shaderbit/typeBits.ts';
import { setName } from '../shared/meta.ts';
import { $gpuCallable, $internal, $ownSnippet, $resolve } from '../shared/symbols.ts';
import type { DualFn, SelfResolvable } from '../types.ts';
import { UnknownData } from './dataTypes.ts';
import { createPtrFromOrigin, explicitFrom } from './ptr.ts';
import { type ResolvedSnippet, snip, type Snippet } from './snippet.ts';
import { isNaturallyEphemeral, isPtr, type Ptr, type StorableData } from './wgslTypes.ts';
import { type ResolvedSnippet, snip, type Snippet, UnknownData } from '../tgsl/snippet.ts';
import { isNaturallyEphemeral, isPtr, type StorableData } from './wgslTypes.ts';

// ----------
// Public API
Expand Down Expand Up @@ -143,9 +143,9 @@ export class RefOperator implements SelfResolvable {
readonly [$internal]: true;
readonly snippet: Snippet;

readonly #ptrType: Ptr | undefined;
readonly #ptrType: PtrBit | undefined;

constructor(snippet: Snippet, ptrType: Ptr | undefined) {
constructor(snippet: Snippet, ptrType: PtrBit | undefined) {
this[$internal] = true;
this.snippet = snippet;
this.#ptrType = ptrType;
Expand All @@ -167,7 +167,7 @@ export class RefOperator implements SelfResolvable {
}

export function derefSnippet(snippet: Snippet): Snippet {
if (!isPtr(snippet.dataType)) {
if (!isPtrType(snippet.dataType)) {
return snippet;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/src/data/schemaCallWrapper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { $cast, $gpuCallable } from '../shared/symbols.ts';
import { type GPUCallable, hasCast, isGPUCallable, type ResolutionCtx } from '../types.ts';
import type { Snippet } from './snippet.ts';
import type { Snippet } from '../tgsl/snippet.ts';
import type { BaseData } from './wgslTypes.ts';

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/src/data/vectorImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { $internal, $resolve } from '../shared/symbols.ts';
import { numericLiteralToSnippet } from '../tgsl/generationHelpers.ts';
import type { ResolutionCtx, SelfResolvable } from '../types.ts';
import { bool, f16, f32, i32, u32 } from './numeric.ts';
import { type ResolvedSnippet } from './snippet.ts';
import { type ResolvedSnippet } from '../tgsl/snippet.ts';
import { WORKAROUND_getSchema, type BaseData, type VecKind } from './wgslTypes.ts';

type ElementSchema<S> = BaseData & ((v?: S) => S);
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/src/data/vertexFormatData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { f32, i32, u32 } from './numeric.ts';
import { vec2f, vec2i, vec2u, vec3f, vec3i, vec3u, vec4f, vec4i, vec4u } from './vector.ts';
import type { WithCast } from '../types.ts';
import { schemaCallWrapper, schemaCallWrapperGPU } from './schemaCallWrapper.ts';
import type { Snippet } from './snippet.ts';
import type { Snippet } from '../tgsl/snippet.ts';
import type {
BaseData,
F16,
Expand Down
2 changes: 1 addition & 1 deletion packages/typegpu/src/resolutionCtx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { getAttributesString } from './data/attributes.ts';
import { isData, undecorate, UnknownData } from './data/dataTypes.ts';
import { bool } from './data/numeric.ts';
import { type ResolvedSnippet, snip, type Snippet } from './data/snippet.ts';
import { type ResolvedSnippet, snip, type Snippet } from './tgsl/snippet.ts';
import { type BaseData, isPtr, isWgslArray, isWgslStruct, Void } from './data/wgslTypes.ts';
import { invariant, MissingSlotValueError, ResolutionError, WgslTypeError } from './errors.ts';
import { provideCtx, topLevelState } from './execMode.ts';
Expand Down
18 changes: 18 additions & 0 deletions packages/typegpu/src/shaderbit/compound.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export interface CompoundBit<T> {
'~shaderbit:wgsl': {
reduce(): T;
};
}

export type ReducibleTo<T> = CompoundBit<T> | T;

export function isCompoundBit(bit: unknown): bit is CompoundBit<unknown> {
return !!(bit as CompoundBit<unknown>)['~shaderbit:wgsl'];
}

export function reduceIfCompound<T>(bit: ReducibleTo<T>): T {
if (isCompoundBit(bit)) {
return bit['~shaderbit:wgsl'].reduce();
}
return bit as T;
}
2 changes: 2 additions & 0 deletions packages/typegpu/src/shaderbit/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './typeBits.ts';
export * from './compound.ts';
Loading
Loading