typegpu 0.10.1 → 0.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{chunk-BYypO7fO.js → _virtual/_rolldown/runtime.js} +1 -1
- package/builtin.d.ts +50 -0
- package/builtin.js +37 -0
- package/common/fullScreenTriangle.d.ts +26 -0
- package/common/fullScreenTriangle.js +36 -0
- package/common/index.d.ts +2 -3
- package/common/index.js +3 -4
- package/core/buffer/buffer.d.ts +74 -0
- package/core/buffer/buffer.js +197 -0
- package/core/buffer/bufferShorthand.d.ts +48 -0
- package/core/buffer/bufferShorthand.js +49 -0
- package/core/buffer/bufferUsage.d.ts +45 -0
- package/core/buffer/bufferUsage.js +163 -0
- package/core/constant/tgpuConstant.d.ts +28 -0
- package/core/constant/tgpuConstant.js +67 -0
- package/core/declare/tgpuDeclare.d.ts +18 -0
- package/core/declare/tgpuDeclare.js +40 -0
- package/core/function/autoIO.d.ts +37 -0
- package/core/function/autoIO.js +87 -0
- package/core/function/comptime.d.ts +39 -0
- package/core/function/comptime.js +51 -0
- package/core/function/createCallableSchema.js +42 -0
- package/core/function/dualImpl.js +54 -0
- package/core/function/extractArgs.js +204 -0
- package/core/function/fnCore.js +79 -0
- package/core/function/fnTypes.d.ts +34 -0
- package/core/function/ioSchema.d.ts +10 -0
- package/core/function/ioSchema.js +30 -0
- package/core/function/shelllessImpl.d.ts +28 -0
- package/core/function/shelllessImpl.js +23 -0
- package/core/function/templateUtils.js +13 -0
- package/core/function/tgpuComputeFn.d.ts +49 -0
- package/core/function/tgpuComputeFn.js +62 -0
- package/core/function/tgpuFn.d.ts +52 -0
- package/core/function/tgpuFn.js +170 -0
- package/core/function/tgpuFragmentFn.d.ts +68 -0
- package/core/function/tgpuFragmentFn.js +68 -0
- package/core/function/tgpuVertexFn.d.ts +55 -0
- package/core/function/tgpuVertexFn.js +65 -0
- package/core/pipeline/applyPipelineState.js +37 -0
- package/core/pipeline/computePipeline.d.ts +58 -0
- package/core/pipeline/computePipeline.js +226 -0
- package/core/pipeline/connectAttachmentToShader.js +26 -0
- package/core/pipeline/connectTargetsToShader.js +29 -0
- package/core/pipeline/limitsOverflow.js +13 -0
- package/core/pipeline/renderPipeline.d.ts +266 -0
- package/core/pipeline/renderPipeline.js +471 -0
- package/core/pipeline/timeable.d.ts +23 -0
- package/core/pipeline/timeable.js +61 -0
- package/core/pipeline/typeGuards.js +29 -0
- package/core/querySet/querySet.d.ts +22 -0
- package/core/querySet/querySet.js +103 -0
- package/core/rawCodeSnippet/tgpuRawCodeSnippet.d.ts +59 -0
- package/core/rawCodeSnippet/tgpuRawCodeSnippet.js +96 -0
- package/core/resolve/externals.d.ts +10 -0
- package/core/resolve/externals.js +58 -0
- package/core/resolve/namespace.d.ts +38 -0
- package/core/resolve/namespace.js +41 -0
- package/core/resolve/resolveData.js +146 -0
- package/core/resolve/stitch.js +25 -0
- package/core/resolve/tgpuResolve.d.ts +151 -0
- package/core/resolve/tgpuResolve.js +68 -0
- package/core/root/configurableImpl.js +18 -0
- package/core/root/init.d.ts +69 -0
- package/core/root/init.js +457 -0
- package/core/root/rootTypes.d.ts +622 -0
- package/core/sampler/sampler.d.ts +35 -0
- package/core/sampler/sampler.js +116 -0
- package/core/simulate/tgpuSimulate.d.ts +36 -0
- package/core/simulate/tgpuSimulate.js +76 -0
- package/core/slot/accessor.d.ts +13 -0
- package/core/slot/accessor.js +97 -0
- package/core/slot/internalSlots.js +7 -0
- package/core/slot/lazy.d.ts +6 -0
- package/core/slot/lazy.js +42 -0
- package/core/slot/slot.d.ts +6 -0
- package/core/slot/slot.js +40 -0
- package/core/slot/slotTypes.d.ts +92 -0
- package/core/slot/slotTypes.js +21 -0
- package/core/texture/externalTexture.d.ts +12 -0
- package/core/texture/externalTexture.js +48 -0
- package/core/texture/texture.d.ts +118 -0
- package/core/texture/texture.js +312 -0
- package/core/texture/textureFormats.d.ts +29 -0
- package/core/texture/textureFormats.js +99 -0
- package/core/texture/textureProps.d.ts +11 -0
- package/core/texture/textureUtils.js +224 -0
- package/core/texture/usageExtension.d.ts +21 -0
- package/core/texture/usageExtension.js +21 -0
- package/core/unroll/tgpuUnroll.d.ts +13 -0
- package/core/unroll/tgpuUnroll.js +36 -0
- package/core/valueProxyUtils.js +44 -0
- package/core/variable/tgpuVariable.d.ts +38 -0
- package/core/variable/tgpuVariable.js +101 -0
- package/core/vertexLayout/connectAttributesToShader.js +59 -0
- package/core/vertexLayout/vertexAttribute.d.ts +29 -0
- package/core/vertexLayout/vertexLayout.d.ts +19 -0
- package/core/vertexLayout/vertexLayout.js +103 -0
- package/data/alignIO.js +15 -0
- package/data/alignmentOf.d.ts +10 -0
- package/data/alignmentOf.js +88 -0
- package/data/array.d.ts +28 -0
- package/data/array.js +48 -0
- package/data/atomic.d.ts +15 -0
- package/data/atomic.js +25 -0
- package/data/attributes.d.ts +121 -0
- package/data/attributes.js +145 -0
- package/data/autoStruct.d.ts +3 -0
- package/data/autoStruct.js +83 -0
- package/data/compiledIO.js +231 -0
- package/data/dataIO.js +549 -0
- package/data/dataTypes.d.ts +115 -0
- package/data/dataTypes.js +97 -0
- package/data/deepEqual.d.ts +25 -0
- package/data/deepEqual.js +58 -0
- package/data/disarray.d.ts +34 -0
- package/data/disarray.js +52 -0
- package/data/getLongestContiguousPrefix.d.ts +10 -0
- package/data/getLongestContiguousPrefix.js +15 -0
- package/data/index.d.ts +26 -4
- package/data/index.js +27 -7
- package/data/instanceToSchema.d.ts +33 -0
- package/data/isContiguous.d.ts +10 -0
- package/data/isContiguous.js +15 -0
- package/data/matrix.d.ts +126 -0
- package/data/matrix.js +517 -0
- package/data/numberOps.js +24 -0
- package/data/numeric.d.ts +81 -0
- package/data/numeric.js +234 -0
- package/data/offsetUtils.d.ts +33 -0
- package/data/offsetUtils.js +167 -0
- package/data/offsets.js +36 -0
- package/data/partialIO.js +68 -0
- package/data/ptr.d.ts +12 -0
- package/data/ptr.js +46 -0
- package/data/ref.d.ts +37 -0
- package/data/ref.js +96 -0
- package/data/sampler.d.ts +107 -0
- package/data/sampler.js +26 -0
- package/data/schemaCallWrapper.js +32 -0
- package/data/schemaMemoryLayout.js +200 -0
- package/data/sizeOf.d.ts +10 -0
- package/data/sizeOf.js +15 -0
- package/data/snippet.d.ts +26 -0
- package/data/snippet.js +61 -0
- package/data/struct.d.ts +17 -0
- package/data/struct.js +46 -0
- package/data/texture.d.ts +292 -0
- package/{texture-BagDrrks.js → data/texture.js} +6 -3
- package/data/unstruct.d.ts +24 -0
- package/data/unstruct.js +43 -0
- package/data/vector.d.ts +191 -0
- package/data/vector.js +247 -0
- package/data/vectorImpl.js +516 -0
- package/data/vectorOps.js +664 -0
- package/data/vertexFormatData.d.ts +190 -0
- package/data/vertexFormatData.js +110 -0
- package/data/wgslTypes.d.ts +896 -0
- package/data/wgslTypes.js +215 -0
- package/errors.d.ts +44 -0
- package/errors.js +128 -0
- package/execMode.js +51 -0
- package/extension.d.ts +11 -0
- package/extension.js +18 -0
- package/getGPUValue.js +9 -0
- package/index.d.ts +40 -243
- package/index.js +19 -6318
- package/indexNamedExports.d.ts +38 -0
- package/mathUtils.js +13 -0
- package/memo.js +22 -0
- package/nameRegistry.d.ts +30 -0
- package/nameRegistry.js +449 -0
- package/package.js +5 -0
- package/package.json +23 -23
- package/resolutionCtx.d.ts +29 -0
- package/resolutionCtx.js +546 -0
- package/shared/env.js +13 -0
- package/shared/generators.js +14 -0
- package/shared/meta.d.ts +39 -0
- package/shared/meta.js +63 -0
- package/shared/repr.d.ts +108 -0
- package/shared/stringify.js +22 -0
- package/shared/symbols.d.ts +61 -0
- package/shared/symbols.js +71 -0
- package/shared/utilityTypes.d.ts +29 -0
- package/shared/utilityTypes.js +7 -0
- package/shared/vertexFormat.d.ts +70 -0
- package/shared/vertexFormat.js +64 -0
- package/std/array.d.ts +7 -0
- package/std/array.js +27 -0
- package/std/atomic.d.ts +19 -0
- package/std/atomic.js +113 -0
- package/std/bitcast.d.ts +10 -0
- package/std/bitcast.js +43 -0
- package/std/boolean.d.ts +127 -0
- package/std/boolean.js +274 -0
- package/std/derivative.d.ts +16 -0
- package/std/derivative.js +89 -0
- package/std/discard.d.ts +6 -0
- package/std/discard.js +16 -0
- package/std/extensions.d.ts +8 -0
- package/std/extensions.js +14 -0
- package/std/index.d.ts +15 -3
- package/std/index.js +16 -5
- package/std/matrix.d.ts +41 -0
- package/std/matrix.js +87 -0
- package/std/numeric.d.ts +254 -0
- package/std/numeric.js +847 -0
- package/std/operators.d.ts +48 -0
- package/std/operators.js +153 -0
- package/std/packing.d.ts +26 -0
- package/std/packing.js +86 -0
- package/std/subgroup.d.ts +47 -0
- package/std/subgroup.js +220 -0
- package/std/texture.d.ts +108 -0
- package/std/texture.js +197 -0
- package/tgpu.js +44 -0
- package/tgpuBindGroupLayout.d.ts +161 -0
- package/tgpuBindGroupLayout.js +271 -0
- package/tgpuUnstable.d.ts +48 -0
- package/tgpuUnstable.js +66 -0
- package/tgsl/accessIndex.js +45 -0
- package/tgsl/accessProp.js +113 -0
- package/tgsl/consoleLog/deserializers.js +117 -0
- package/tgsl/consoleLog/logGenerator.js +86 -0
- package/tgsl/consoleLog/serializers.js +225 -0
- package/tgsl/consoleLog/types.d.ts +54 -0
- package/tgsl/consoleLog/types.js +12 -0
- package/tgsl/conversion.js +200 -0
- package/tgsl/forOfUtils.js +45 -0
- package/tgsl/generationHelpers.d.ts +37 -0
- package/tgsl/generationHelpers.js +67 -0
- package/tgsl/math.js +45 -0
- package/tgsl/shaderGenerator.d.ts +18 -0
- package/tgsl/shellless.d.ts +11 -0
- package/tgsl/shellless.js +53 -0
- package/tgsl/wgslGenerator.js +585 -0
- package/types.d.ts +255 -0
- package/types.js +43 -0
- package/unwrapper.d.ts +27 -0
- package/wgslExtensions.d.ts +5 -0
- package/wgslExtensions.js +18 -0
- package/builtin-DdtWpk2t.js +0 -818
- package/builtin-DdtWpk2t.js.map +0 -1
- package/common/index.d.ts.map +0 -1
- package/common/index.js.map +0 -1
- package/data/index.d.ts.map +0 -1
- package/data/index.js.map +0 -1
- package/deepEqual-DQxK4vdp.js +0 -413
- package/deepEqual-DQxK4vdp.js.map +0 -1
- package/extensions-DIVuAfBM.js +0 -2032
- package/extensions-DIVuAfBM.js.map +0 -1
- package/fullScreenTriangle-CfFyQd_0.js +0 -543
- package/fullScreenTriangle-CfFyQd_0.js.map +0 -1
- package/index.d.ts.map +0 -1
- package/index.js.map +0 -1
- package/indexNamedExports-oL6tyaJ9.d.ts +0 -5697
- package/indexNamedExports-oL6tyaJ9.d.ts.map +0 -1
- package/operators-d-PMVTo7.js +0 -4158
- package/operators-d-PMVTo7.js.map +0 -1
- package/std/index.d.ts.map +0 -1
- package/std/index.js.map +0 -1
- package/texture-BagDrrks.js.map +0 -1
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { TgpuNamable } from "../../shared/meta.js";
|
|
2
|
+
import { $gpuValueOf, $internal } from "../../shared/symbols.js";
|
|
3
|
+
import { Default, TypedArray, UnionToIntersection } from "../../shared/utilityTypes.js";
|
|
4
|
+
import "../../data/snippet.js";
|
|
5
|
+
import { TextureProps } from "./textureProps.js";
|
|
6
|
+
import { AllowedUsages, LiteralToExtensionMap } from "./usageExtension.js";
|
|
7
|
+
import "../../tgpuBindGroupLayout.js";
|
|
8
|
+
import "../root/rootTypes.js";
|
|
9
|
+
import "../../types.js";
|
|
10
|
+
import { F32 } from "../../data/wgslTypes.js";
|
|
11
|
+
import { TextureFormats, ViewDimensionToDimension } from "./textureFormats.js";
|
|
12
|
+
import { TextureSchemaForDescriptor, WgslStorageTexture, WgslTexture } from "../../data/texture.js";
|
|
13
|
+
import { Infer, ValidateTextureViewSchema } from "../../shared/repr.js";
|
|
14
|
+
|
|
15
|
+
//#region src/core/texture/texture.d.ts
|
|
16
|
+
type TextureInternals = {
|
|
17
|
+
unwrap(): GPUTexture;
|
|
18
|
+
};
|
|
19
|
+
type TextureViewInternals = {
|
|
20
|
+
readonly unwrap: (() => GPUTextureView) | undefined;
|
|
21
|
+
};
|
|
22
|
+
type ExternalImageSource = HTMLCanvasElement | HTMLImageElement | HTMLVideoElement | ImageBitmap | ImageData | OffscreenCanvas | VideoFrame;
|
|
23
|
+
type TgpuTextureViewDescriptor = {
|
|
24
|
+
/**
|
|
25
|
+
* Which {@link GPUTextureAspect | aspect(s)} of the texture are accessible to the texture view.
|
|
26
|
+
*/
|
|
27
|
+
aspect?: GPUTextureAspect;
|
|
28
|
+
/**
|
|
29
|
+
* The first (most detailed) mipmap level accessible to the texture view.
|
|
30
|
+
*/
|
|
31
|
+
baseMipLevel?: GPUIntegerCoordinate;
|
|
32
|
+
/**
|
|
33
|
+
* How many mipmap levels, starting with {@link GPUTextureViewDescriptor#baseMipLevel}, are accessible to
|
|
34
|
+
* the texture view.
|
|
35
|
+
*/
|
|
36
|
+
mipLevelCount?: GPUIntegerCoordinate;
|
|
37
|
+
/**
|
|
38
|
+
* The index of the first array layer accessible to the texture view.
|
|
39
|
+
*/
|
|
40
|
+
baseArrayLayer?: GPUIntegerCoordinate;
|
|
41
|
+
/**
|
|
42
|
+
* How many array layers, starting with {@link GPUTextureViewDescriptor#baseArrayLayer}, are accessible
|
|
43
|
+
* to the texture view.
|
|
44
|
+
*/
|
|
45
|
+
arrayLayerCount?: GPUIntegerCoordinate;
|
|
46
|
+
/**
|
|
47
|
+
* The format of the texture view. Must be either the {@link GPUTextureDescriptor#format} of the
|
|
48
|
+
* texture or one of the {@link GPUTextureDescriptor#viewFormats} specified during its creation.
|
|
49
|
+
*/
|
|
50
|
+
format?: GPUTextureFormat;
|
|
51
|
+
};
|
|
52
|
+
type DefaultViewSchema<T extends Partial<TextureProps>> = TextureSchemaForDescriptor<{
|
|
53
|
+
dimension: Default<T['dimension'], '2d'>;
|
|
54
|
+
sampleType: T['format'] extends keyof TextureFormats ? TextureFormats[T['format']]['channelType'] : TextureFormats[keyof TextureFormats]['channelType'];
|
|
55
|
+
multisampled: Default<T['sampleCount'], 1> extends 1 ? false : true;
|
|
56
|
+
}>;
|
|
57
|
+
type BaseDimension<T extends string> = T extends keyof ViewDimensionToDimension ? ViewDimensionToDimension[T] : never;
|
|
58
|
+
type OptionalDimension<T extends string> = T extends '2d' | '2d-array' | 'cube' | 'cube-array' ? {
|
|
59
|
+
dimension?: BaseDimension<T>;
|
|
60
|
+
} : {
|
|
61
|
+
dimension: BaseDimension<T>;
|
|
62
|
+
};
|
|
63
|
+
type MultisampledProps<T extends WgslTexture> = T['multisampled'] extends true ? OptionalDimension<T['dimension']> & {
|
|
64
|
+
sampleCount: 4;
|
|
65
|
+
} : OptionalDimension<T['dimension']> & {
|
|
66
|
+
sampleCount?: 1;
|
|
67
|
+
};
|
|
68
|
+
type PropsForSchema<T extends WgslTexture | WgslStorageTexture> = T extends WgslTexture ? {
|
|
69
|
+
size: readonly number[];
|
|
70
|
+
format: GPUTextureFormat;
|
|
71
|
+
} & MultisampledProps<T> : T extends WgslStorageTexture ? {
|
|
72
|
+
size: readonly number[];
|
|
73
|
+
format: T['format'];
|
|
74
|
+
} & OptionalDimension<T['dimension']> : never;
|
|
75
|
+
type CopyCompatibleTexture<T extends TextureProps> = TgpuTexture<{
|
|
76
|
+
size: T['size'];
|
|
77
|
+
format: T['format'];
|
|
78
|
+
sampleCount?: T['sampleCount'];
|
|
79
|
+
}>;
|
|
80
|
+
interface TgpuTexture<TProps extends TextureProps = any> extends TgpuNamable {
|
|
81
|
+
readonly [$internal]: TextureInternals;
|
|
82
|
+
readonly resourceType: 'texture';
|
|
83
|
+
readonly props: TProps;
|
|
84
|
+
readonly destroyed: boolean;
|
|
85
|
+
readonly usableAsStorage: boolean;
|
|
86
|
+
readonly usableAsSampled: boolean;
|
|
87
|
+
readonly usableAsRender: boolean;
|
|
88
|
+
$usage<T extends AllowedUsages<TProps>[]>(...usages: T): this & UnionToIntersection<LiteralToExtensionMap[T[number]]>;
|
|
89
|
+
createView(...args: this['usableAsSampled'] extends true ? [] : [ValidateTextureViewSchema<this, WgslTexture>]): TgpuTextureView<DefaultViewSchema<TProps>>;
|
|
90
|
+
createView(schema: 'render', viewDescriptor?: TgpuTextureViewDescriptor): TgpuTextureRenderView;
|
|
91
|
+
createView<T extends WgslTexture>(schema: ValidateTextureViewSchema<this, T>, viewDescriptor?: TgpuTextureViewDescriptor & {
|
|
92
|
+
sampleType?: T['sampleType'] extends F32 ? 'float' | 'unfilterable-float' : never;
|
|
93
|
+
}): TgpuTextureView<T>;
|
|
94
|
+
createView<T extends WgslStorageTexture>(schema: ValidateTextureViewSchema<this, T>, viewDescriptor?: TgpuTextureViewDescriptor): TgpuTextureView<T>;
|
|
95
|
+
clear(mipLevel?: number | 'all'): void;
|
|
96
|
+
generateMipmaps(baseMipLevel?: number, mipLevels?: number): void;
|
|
97
|
+
write(source: ExternalImageSource | ExternalImageSource[]): void;
|
|
98
|
+
write(source: ArrayBuffer | TypedArray | DataView, mipLevel?: number): void;
|
|
99
|
+
copyFrom<T extends CopyCompatibleTexture<TProps>>(source: T): void;
|
|
100
|
+
destroy(): void;
|
|
101
|
+
}
|
|
102
|
+
interface TgpuTextureView<TSchema extends WgslStorageTexture | WgslTexture = WgslStorageTexture | WgslTexture> extends TgpuNamable {
|
|
103
|
+
readonly [$internal]: TextureViewInternals;
|
|
104
|
+
readonly resourceType: 'texture-view';
|
|
105
|
+
readonly schema: TSchema;
|
|
106
|
+
readonly size?: number[] | undefined;
|
|
107
|
+
readonly [$gpuValueOf]: Infer<TSchema>;
|
|
108
|
+
value: Infer<TSchema>;
|
|
109
|
+
$: Infer<TSchema>;
|
|
110
|
+
}
|
|
111
|
+
interface TgpuTextureRenderView {
|
|
112
|
+
readonly [$internal]: TextureViewInternals;
|
|
113
|
+
readonly resourceType: 'texture-view';
|
|
114
|
+
readonly descriptor: TgpuTextureViewDescriptor;
|
|
115
|
+
}
|
|
116
|
+
declare function isTexture(value: unknown): value is TgpuTexture;
|
|
117
|
+
//#endregion
|
|
118
|
+
export { PropsForSchema, TextureInternals, TgpuTexture, TgpuTextureRenderView, TgpuTextureView, isTexture };
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import { $gpuValueOf, $internal, $ownSnippet, $resolve } from "../../shared/symbols.js";
|
|
2
|
+
import { getName, setName } from "../../shared/meta.js";
|
|
3
|
+
import { snip } from "../../data/snippet.js";
|
|
4
|
+
import { inCodegenMode } from "../../execMode.js";
|
|
5
|
+
import { valueProxyHandler } from "../valueProxyUtils.js";
|
|
6
|
+
import { isWgslStorageTexture, textureDescriptorToSchema } from "../../data/texture.js";
|
|
7
|
+
import { getTextureFormatInfo } from "./textureFormats.js";
|
|
8
|
+
import { generateTextureMipmaps, getImageSourceDimensions, resampleImage } from "./textureUtils.js";
|
|
9
|
+
|
|
10
|
+
//#region src/core/texture/texture.ts
|
|
11
|
+
function getDescriptorForProps(props) {
|
|
12
|
+
return {
|
|
13
|
+
dimension: props.dimension ?? "2d",
|
|
14
|
+
sampleType: getTextureFormatInfo(props.format).channelType,
|
|
15
|
+
multisampled: !((props.sampleCount ?? 1) === 1)
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function INTERNAL_createTexture(props, branch) {
|
|
19
|
+
return new TgpuTextureImpl(props, branch);
|
|
20
|
+
}
|
|
21
|
+
function isTexture(value) {
|
|
22
|
+
return value?.resourceType === "texture" && !!value[$internal];
|
|
23
|
+
}
|
|
24
|
+
function isTextureView(value) {
|
|
25
|
+
return value?.resourceType === "texture-view" && !!value[$internal];
|
|
26
|
+
}
|
|
27
|
+
var TgpuTextureImpl = class {
|
|
28
|
+
[$internal];
|
|
29
|
+
resourceType = "texture";
|
|
30
|
+
usableAsSampled = false;
|
|
31
|
+
usableAsStorage = false;
|
|
32
|
+
usableAsRender = false;
|
|
33
|
+
#formatInfo;
|
|
34
|
+
#destroyed = false;
|
|
35
|
+
#flags = GPUTextureUsage.COPY_DST | GPUTextureUsage.COPY_SRC;
|
|
36
|
+
#texture = null;
|
|
37
|
+
#branch;
|
|
38
|
+
constructor(props, branch) {
|
|
39
|
+
this.props = props;
|
|
40
|
+
const format = props.format;
|
|
41
|
+
this.#branch = branch;
|
|
42
|
+
this.#formatInfo = getTextureFormatInfo(format);
|
|
43
|
+
this[$internal] = { unwrap: () => {
|
|
44
|
+
if (this.#destroyed) throw new Error("This texture has been destroyed");
|
|
45
|
+
if (!this.#texture) this.#texture = branch.device.createTexture({
|
|
46
|
+
label: getName(this) ?? "<unnamed>",
|
|
47
|
+
format: props.format,
|
|
48
|
+
size: props.size,
|
|
49
|
+
usage: this.#flags,
|
|
50
|
+
dimension: props.dimension ?? "2d",
|
|
51
|
+
viewFormats: props.viewFormats ?? [],
|
|
52
|
+
mipLevelCount: props.mipLevelCount ?? 1,
|
|
53
|
+
sampleCount: props.sampleCount ?? 1
|
|
54
|
+
});
|
|
55
|
+
return this.#texture;
|
|
56
|
+
} };
|
|
57
|
+
}
|
|
58
|
+
$name(label) {
|
|
59
|
+
setName(this, label);
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
$usage(...usages) {
|
|
63
|
+
const hasStorage = usages.includes("storage");
|
|
64
|
+
const hasSampled = usages.includes("sampled");
|
|
65
|
+
const hasRender = usages.includes("render");
|
|
66
|
+
this.#flags |= hasSampled ? GPUTextureUsage.TEXTURE_BINDING : 0;
|
|
67
|
+
this.#flags |= hasStorage ? GPUTextureUsage.STORAGE_BINDING : 0;
|
|
68
|
+
this.#flags |= hasRender ? GPUTextureUsage.RENDER_ATTACHMENT : 0;
|
|
69
|
+
this.usableAsStorage ||= hasStorage;
|
|
70
|
+
this.usableAsSampled ||= hasSampled;
|
|
71
|
+
this.usableAsRender ||= hasRender;
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
74
|
+
createView(schema, viewDescriptor) {
|
|
75
|
+
if (schema === "render") return new TgpuTextureRenderViewImpl(this, viewDescriptor);
|
|
76
|
+
return new TgpuFixedTextureViewImpl(schema ?? textureDescriptorToSchema(getDescriptorForProps(this.props)), this, viewDescriptor);
|
|
77
|
+
}
|
|
78
|
+
#clearMipLevel(mip = 0) {
|
|
79
|
+
const scale = 2 ** mip;
|
|
80
|
+
const [width, height, depth] = [
|
|
81
|
+
Math.max(1, Math.floor((this.props.size[0] ?? 1) / scale)),
|
|
82
|
+
Math.max(1, Math.floor((this.props.size[1] ?? 1) / scale)),
|
|
83
|
+
Math.max(1, Math.floor((this.props.size[2] ?? 1) / scale))
|
|
84
|
+
];
|
|
85
|
+
const texelSize = this.#formatInfo.texelSize;
|
|
86
|
+
if (texelSize === "non-copyable") throw new Error(`Cannot clear texture with format '${this.props.format}': this format does not support copy operations.`);
|
|
87
|
+
this.#branch.device.queue.writeTexture({
|
|
88
|
+
texture: this[$internal].unwrap(),
|
|
89
|
+
mipLevel: mip
|
|
90
|
+
}, new Uint8Array(width * height * depth * texelSize), {
|
|
91
|
+
bytesPerRow: texelSize * width,
|
|
92
|
+
rowsPerImage: height
|
|
93
|
+
}, [
|
|
94
|
+
width,
|
|
95
|
+
height,
|
|
96
|
+
depth
|
|
97
|
+
]);
|
|
98
|
+
}
|
|
99
|
+
clear(mipLevel = "all") {
|
|
100
|
+
if (mipLevel === "all") {
|
|
101
|
+
const mipLevels = this.props.mipLevelCount ?? 1;
|
|
102
|
+
for (let i = 0; i < mipLevels; i++) this.#clearMipLevel(i);
|
|
103
|
+
} else this.#clearMipLevel(mipLevel);
|
|
104
|
+
}
|
|
105
|
+
generateMipmaps(baseMipLevel = 0, mipLevels) {
|
|
106
|
+
if (!this.usableAsRender) throw new Error("generateMipmaps called without specifying 'render' usage. Add it via the $usage('render') method.");
|
|
107
|
+
const actualMipLevels = mipLevels ?? (this.props.mipLevelCount ?? 1) - baseMipLevel;
|
|
108
|
+
if (actualMipLevels <= 1) {
|
|
109
|
+
console.warn(`generateMipmaps is a no-op: would generate ${actualMipLevels} mip levels (base: ${baseMipLevel}, total: ${this.props.mipLevelCount ?? 1})`);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
if (baseMipLevel >= (this.props.mipLevelCount ?? 1)) throw new Error(`Base mip level ${baseMipLevel} is out of range. Texture has ${this.props.mipLevelCount ?? 1} mip levels.`);
|
|
113
|
+
generateTextureMipmaps(this.#branch.device, this[$internal].unwrap(), baseMipLevel, actualMipLevels);
|
|
114
|
+
}
|
|
115
|
+
write(source, mipLevel = 0) {
|
|
116
|
+
if (source instanceof ArrayBuffer || ArrayBuffer.isView(source)) {
|
|
117
|
+
this.#writeBufferData(source, mipLevel);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const dimension = this.props.dimension ?? "2d";
|
|
121
|
+
if (!Array.isArray(source)) {
|
|
122
|
+
this.#writeSingleLayer(source, dimension === "3d" ? 0 : void 0);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const layerCount = this.props.size[2] ?? 1;
|
|
126
|
+
if (source.length > layerCount) console.warn(`Too many image sources provided. Expected ${layerCount} layers, got ${source.length}. Extra sources will be ignored.`);
|
|
127
|
+
for (let layer = 0; layer < Math.min(source.length, layerCount); layer++) {
|
|
128
|
+
const bitmap = source[layer];
|
|
129
|
+
if (bitmap) this.#writeSingleLayer(bitmap, layer);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
#writeBufferData(source, mipLevel) {
|
|
133
|
+
const mipWidth = Math.max(1, this.props.size[0] >> mipLevel);
|
|
134
|
+
const mipHeight = Math.max(1, (this.props.size[1] ?? 1) >> mipLevel);
|
|
135
|
+
const mipDepth = Math.max(1, (this.props.size[2] ?? 1) >> mipLevel);
|
|
136
|
+
const texelSize = this.#formatInfo.texelSize;
|
|
137
|
+
if (texelSize === "non-copyable") throw new Error(`Cannot write to texture with format '${this.props.format}': this format does not support copy operations.`);
|
|
138
|
+
const expectedSize = mipWidth * mipHeight * mipDepth * texelSize;
|
|
139
|
+
const actualSize = source.byteLength ?? source.byteLength;
|
|
140
|
+
if (actualSize !== expectedSize) throw new Error(`Buffer size mismatch. Expected ${expectedSize} bytes for mip level ${mipLevel}, got ${actualSize} bytes.`);
|
|
141
|
+
this.#branch.device.queue.writeTexture({
|
|
142
|
+
texture: this[$internal].unwrap(),
|
|
143
|
+
mipLevel
|
|
144
|
+
}, "buffer" in source ? source.buffer : source, {
|
|
145
|
+
bytesPerRow: texelSize * mipWidth,
|
|
146
|
+
rowsPerImage: mipHeight
|
|
147
|
+
}, [
|
|
148
|
+
mipWidth,
|
|
149
|
+
mipHeight,
|
|
150
|
+
mipDepth
|
|
151
|
+
]);
|
|
152
|
+
}
|
|
153
|
+
#writeSingleLayer(source, layer) {
|
|
154
|
+
const targetWidth = this.props.size[0];
|
|
155
|
+
const targetHeight = this.props.size[1] ?? 1;
|
|
156
|
+
const { width: sourceWidth, height: sourceHeight } = getImageSourceDimensions(source);
|
|
157
|
+
if (sourceWidth !== targetWidth || sourceHeight !== targetHeight) {
|
|
158
|
+
resampleImage(this.#branch.device, this[$internal].unwrap(), source, layer);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
this.#branch.device.queue.copyExternalImageToTexture({ source }, {
|
|
162
|
+
texture: this[$internal].unwrap(),
|
|
163
|
+
...layer !== void 0 && { origin: {
|
|
164
|
+
x: 0,
|
|
165
|
+
y: 0,
|
|
166
|
+
z: layer
|
|
167
|
+
} }
|
|
168
|
+
}, layer !== void 0 ? [
|
|
169
|
+
targetWidth,
|
|
170
|
+
targetHeight,
|
|
171
|
+
1
|
|
172
|
+
] : this.props.size);
|
|
173
|
+
}
|
|
174
|
+
copyFrom(source) {
|
|
175
|
+
if (source.props.format !== this.props.format) throw new Error(`Texture format mismatch. Source texture has format ${source.props.format}, target texture has format ${this.props.format}`);
|
|
176
|
+
if (source.props.size[0] !== this.props.size[0] || (source.props.size[1] ?? 1) !== (this.props.size[1] ?? 1) || (source.props.size[2] ?? 1) !== (this.props.size[2] ?? 1)) throw new Error(`Texture size mismatch. Source texture has size ${source.props.size.join("x")}, target texture has size ${this.props.size.join("x")}`);
|
|
177
|
+
const commandEncoder = this.#branch.device.createCommandEncoder();
|
|
178
|
+
commandEncoder.copyTextureToTexture({ texture: source[$internal].unwrap() }, { texture: this[$internal].unwrap() }, source.props.size);
|
|
179
|
+
this.#branch.device.queue.submit([commandEncoder.finish()]);
|
|
180
|
+
}
|
|
181
|
+
toString() {
|
|
182
|
+
return `${this.resourceType}:${getName(this) ?? "<unnamed>"}`;
|
|
183
|
+
}
|
|
184
|
+
get destroyed() {
|
|
185
|
+
return this.#destroyed;
|
|
186
|
+
}
|
|
187
|
+
destroy() {
|
|
188
|
+
if (this.#destroyed) return;
|
|
189
|
+
this.#destroyed = true;
|
|
190
|
+
this.#texture?.destroy();
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
var TgpuFixedTextureViewImpl = class {
|
|
194
|
+
[$internal];
|
|
195
|
+
resourceType = "texture-view";
|
|
196
|
+
#baseTexture;
|
|
197
|
+
#view;
|
|
198
|
+
#descriptor;
|
|
199
|
+
constructor(schema, baseTexture, descriptor) {
|
|
200
|
+
this.schema = schema;
|
|
201
|
+
this.#baseTexture = baseTexture;
|
|
202
|
+
this.#descriptor = descriptor;
|
|
203
|
+
this[$internal] = { unwrap: () => {
|
|
204
|
+
if (!this.#view) {
|
|
205
|
+
const schema = this.schema;
|
|
206
|
+
const format = isWgslStorageTexture(schema) ? schema.format : this.#baseTexture.props.format;
|
|
207
|
+
this.#view = this.#baseTexture[$internal].unwrap().createView({
|
|
208
|
+
...this.#descriptor,
|
|
209
|
+
label: getName(this) ?? "<unnamed>",
|
|
210
|
+
format: this.#descriptor?.format ?? format,
|
|
211
|
+
dimension: schema.dimension
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
return this.#view;
|
|
215
|
+
} };
|
|
216
|
+
}
|
|
217
|
+
$name(label) {
|
|
218
|
+
setName(this, label);
|
|
219
|
+
if (this.#view) this.#view.label = label;
|
|
220
|
+
return this;
|
|
221
|
+
}
|
|
222
|
+
get [$gpuValueOf]() {
|
|
223
|
+
const schema = this.schema;
|
|
224
|
+
return new Proxy({
|
|
225
|
+
[$internal]: true,
|
|
226
|
+
get [$ownSnippet]() {
|
|
227
|
+
return snip(this, schema, "handle");
|
|
228
|
+
},
|
|
229
|
+
[$resolve]: (ctx) => ctx.resolve(this),
|
|
230
|
+
toString: () => `${this.toString()}.$`
|
|
231
|
+
}, valueProxyHandler);
|
|
232
|
+
}
|
|
233
|
+
get $() {
|
|
234
|
+
if (inCodegenMode()) return this[$gpuValueOf];
|
|
235
|
+
throw new Error("Direct access to texture view values is possible only as part of a compute dispatch or draw call. Try .read() or .write() instead");
|
|
236
|
+
}
|
|
237
|
+
get value() {
|
|
238
|
+
return this.$;
|
|
239
|
+
}
|
|
240
|
+
get size() {
|
|
241
|
+
return this.#baseTexture.props.size;
|
|
242
|
+
}
|
|
243
|
+
toString() {
|
|
244
|
+
return `textureView:${getName(this) ?? "<unnamed>"}`;
|
|
245
|
+
}
|
|
246
|
+
[$resolve](ctx) {
|
|
247
|
+
const id = ctx.getUniqueName(this);
|
|
248
|
+
const { group, binding } = ctx.allocateFixedEntry(isWgslStorageTexture(this.schema) ? { storageTexture: this.schema } : {
|
|
249
|
+
texture: this.schema,
|
|
250
|
+
sampleType: this.#descriptor?.sampleType ?? this.schema.bindingSampleType[0]
|
|
251
|
+
}, this);
|
|
252
|
+
ctx.addDeclaration(`@group(${group}) @binding(${binding}) var ${id}: ${ctx.resolve(this.schema).value};`);
|
|
253
|
+
return snip(id, this.schema, "handle");
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
var TgpuLaidOutTextureViewImpl = class {
|
|
257
|
+
[$internal] = { unwrap: void 0 };
|
|
258
|
+
resourceType = "texture-view";
|
|
259
|
+
#membership;
|
|
260
|
+
constructor(schema, membership) {
|
|
261
|
+
this.schema = schema;
|
|
262
|
+
this.#membership = membership;
|
|
263
|
+
setName(this, membership.key);
|
|
264
|
+
}
|
|
265
|
+
toString() {
|
|
266
|
+
return `textureView:${getName(this) ?? "<unnamed>"}`;
|
|
267
|
+
}
|
|
268
|
+
[$resolve](ctx) {
|
|
269
|
+
const id = ctx.getUniqueName(this);
|
|
270
|
+
const group = ctx.allocateLayoutEntry(this.#membership.layout);
|
|
271
|
+
ctx.addDeclaration(`@group(${group}) @binding(${this.#membership.idx}) var ${id}: ${ctx.resolve(this.schema).value};`);
|
|
272
|
+
return snip(id, this.schema, "handle");
|
|
273
|
+
}
|
|
274
|
+
get [$gpuValueOf]() {
|
|
275
|
+
const schema = this.schema;
|
|
276
|
+
return new Proxy({
|
|
277
|
+
[$internal]: true,
|
|
278
|
+
get [$ownSnippet]() {
|
|
279
|
+
return snip(this, schema, "handle");
|
|
280
|
+
},
|
|
281
|
+
[$resolve]: (ctx) => ctx.resolve(this),
|
|
282
|
+
toString: () => `${this.toString()}.$`
|
|
283
|
+
}, valueProxyHandler);
|
|
284
|
+
}
|
|
285
|
+
get $() {
|
|
286
|
+
if (inCodegenMode()) return this[$gpuValueOf];
|
|
287
|
+
throw new Error(`Accessed view '${getName(this) ?? "<unnamed>"}' outside of codegen mode. Direct access to texture views values is possible only as part of a compute dispatch or draw call. Try .read() or .write() instead`);
|
|
288
|
+
}
|
|
289
|
+
get value() {
|
|
290
|
+
return this.$;
|
|
291
|
+
}
|
|
292
|
+
$name(label) {
|
|
293
|
+
setName(this, label);
|
|
294
|
+
return this;
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
var TgpuTextureRenderViewImpl = class {
|
|
298
|
+
[$internal];
|
|
299
|
+
resourceType = "texture-view";
|
|
300
|
+
constructor(baseTexture, descriptor = {}) {
|
|
301
|
+
this.descriptor = descriptor;
|
|
302
|
+
this[$internal] = { unwrap: () => {
|
|
303
|
+
return baseTexture[$internal].unwrap().createView({
|
|
304
|
+
label: getName(this) ?? "<unnamed>",
|
|
305
|
+
...this.descriptor
|
|
306
|
+
});
|
|
307
|
+
} };
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
//#endregion
|
|
312
|
+
export { INTERNAL_createTexture, TgpuLaidOutTextureViewImpl, isTexture, isTextureView };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { F32, I32, U32, Vec4f, Vec4i, Vec4u } from "../../data/wgslTypes.js";
|
|
2
|
+
|
|
3
|
+
//#region src/core/texture/textureFormats.d.ts
|
|
4
|
+
type ViewDimensionToDimension = {
|
|
5
|
+
'1d': '1d';
|
|
6
|
+
'2d': '2d';
|
|
7
|
+
'2d-array': '2d';
|
|
8
|
+
'3d': '3d';
|
|
9
|
+
cube: '2d';
|
|
10
|
+
'cube-array': '2d';
|
|
11
|
+
};
|
|
12
|
+
type StorageTextureFormats = 'rgba8unorm' | 'rgba8snorm' | 'rgba8uint' | 'rgba8sint' | 'rgba16unorm' | 'rgba16snorm' | 'rgba16uint' | 'rgba16sint' | 'rgba16float' | 'rg8unorm' | 'rg8snorm' | 'rg8uint' | 'rg8sint' | 'rg16unorm' | 'rg16snorm' | 'rg16uint' | 'rg16sint' | 'rg16float' | 'r32uint' | 'r32sint' | 'r32float' | 'rg32uint' | 'rg32sint' | 'rg32float' | 'rgba32uint' | 'rgba32sint' | 'rgba32float' | 'bgra8unorm' | 'r8unorm' | 'r8snorm' | 'r8uint' | 'r8sint' | 'r16unorm' | 'r16snorm' | 'r16uint' | 'r16sint' | 'r16float' | 'rgb10a2unorm' | 'rgb10a2uint' | 'rg11b10ufloat';
|
|
13
|
+
type ParseChannelType<T extends GPUTextureFormat> = T extends `${string}uint${string}` ? 'u32' : T extends `${string}sint${string}` ? 'i32' : 'f32';
|
|
14
|
+
type ChannelTypeToSampleType<T extends 'f32' | 'i32' | 'u32'> = {
|
|
15
|
+
f32: F32;
|
|
16
|
+
i32: I32;
|
|
17
|
+
u32: U32;
|
|
18
|
+
}[T];
|
|
19
|
+
type ChannelTypeToVectorType<T extends 'f32' | 'i32' | 'u32'> = {
|
|
20
|
+
f32: Vec4f;
|
|
21
|
+
i32: Vec4i;
|
|
22
|
+
u32: Vec4u;
|
|
23
|
+
}[T];
|
|
24
|
+
type TextureFormats = { [K in GPUTextureFormat]: {
|
|
25
|
+
channelType: ChannelTypeToSampleType<ParseChannelType<K>>;
|
|
26
|
+
vectorType: ChannelTypeToVectorType<ParseChannelType<K>>;
|
|
27
|
+
} };
|
|
28
|
+
//#endregion
|
|
29
|
+
export { StorageTextureFormats, TextureFormats, ViewDimensionToDimension };
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { f32, i32, u32 } from "../../data/numeric.js";
|
|
2
|
+
import { vec4f, vec4i, vec4u } from "../../data/vector.js";
|
|
3
|
+
|
|
4
|
+
//#region src/core/texture/textureFormats.ts
|
|
5
|
+
const DEPTH_ASPECT_NON_COPYABLE = {
|
|
6
|
+
channelType: f32,
|
|
7
|
+
vectorType: vec4f,
|
|
8
|
+
sampleTypes: ["depth", "unfilterable-float"],
|
|
9
|
+
texelSize: "non-copyable"
|
|
10
|
+
};
|
|
11
|
+
const DEPTH_ASPECT_16 = {
|
|
12
|
+
channelType: f32,
|
|
13
|
+
vectorType: vec4f,
|
|
14
|
+
sampleTypes: ["depth", "unfilterable-float"],
|
|
15
|
+
texelSize: 2
|
|
16
|
+
};
|
|
17
|
+
const DEPTH_ASPECT_32 = {
|
|
18
|
+
channelType: f32,
|
|
19
|
+
vectorType: vec4f,
|
|
20
|
+
sampleTypes: ["depth", "unfilterable-float"],
|
|
21
|
+
texelSize: 4
|
|
22
|
+
};
|
|
23
|
+
const STENCIL_ASPECT = {
|
|
24
|
+
channelType: u32,
|
|
25
|
+
vectorType: vec4u,
|
|
26
|
+
sampleTypes: ["uint"],
|
|
27
|
+
texelSize: 1
|
|
28
|
+
};
|
|
29
|
+
const formatInfoCache = /* @__PURE__ */ new Map();
|
|
30
|
+
function getTextureFormatInfo(format) {
|
|
31
|
+
let info = formatInfoCache.get(format);
|
|
32
|
+
if (info === void 0) {
|
|
33
|
+
info = createFormatInfo(format);
|
|
34
|
+
formatInfoCache.set(format, info);
|
|
35
|
+
}
|
|
36
|
+
return info;
|
|
37
|
+
}
|
|
38
|
+
function createFormatInfo(format) {
|
|
39
|
+
const channelType = parseChannelType(format);
|
|
40
|
+
const depthAspect = getDepthAspect(format);
|
|
41
|
+
const hasStencil = format.includes("stencil");
|
|
42
|
+
return {
|
|
43
|
+
channelType,
|
|
44
|
+
vectorType: channelType === u32 ? vec4u : channelType === i32 ? vec4i : vec4f,
|
|
45
|
+
texelSize: parseTexelSize(format),
|
|
46
|
+
sampleTypes: parseSampleTypes(format),
|
|
47
|
+
canRenderAttachment: canRenderAttachment(format),
|
|
48
|
+
...depthAspect && { depthAspect },
|
|
49
|
+
...hasStencil && { stencilAspect: STENCIL_ASPECT }
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function getDepthAspect(format) {
|
|
53
|
+
if (format === "depth16unorm") return DEPTH_ASPECT_16;
|
|
54
|
+
if (format === "depth32float" || format === "depth32float-stencil8") return DEPTH_ASPECT_32;
|
|
55
|
+
if (format === "depth24plus" || format === "depth24plus-stencil8") return DEPTH_ASPECT_NON_COPYABLE;
|
|
56
|
+
}
|
|
57
|
+
function canRenderAttachment(format) {
|
|
58
|
+
if (format.startsWith("bc") || format.startsWith("etc2") || format.startsWith("eac") || format.startsWith("astc")) return false;
|
|
59
|
+
if (format === "rgb9e5ufloat") return false;
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
function parseChannelType(format) {
|
|
63
|
+
if (format === "stencil8") return u32;
|
|
64
|
+
if (format.includes("uint")) return u32;
|
|
65
|
+
if (format.includes("sint")) return i32;
|
|
66
|
+
return f32;
|
|
67
|
+
}
|
|
68
|
+
function parseTexelSize(format) {
|
|
69
|
+
const [, channels, bits] = format.match(/^(rgba|bgra|rg|r)(8|16|32)/) ?? [];
|
|
70
|
+
if (channels && bits) return channels.length * Number(bits) / 8;
|
|
71
|
+
if (format === "stencil8") return 1;
|
|
72
|
+
if (format === "depth16unorm") return 2;
|
|
73
|
+
if (format === "depth32float") return 4;
|
|
74
|
+
if (format === "depth32float-stencil8") return 5;
|
|
75
|
+
if (format === "depth24plus" || format === "depth24plus-stencil8") return "non-copyable";
|
|
76
|
+
if (/^(bc[14]-|etc2-rgb8|eac-r11)/.test(format)) return 8;
|
|
77
|
+
if (/^(bc|astc-|etc2-rgba|eac-rg)/.test(format)) return 16;
|
|
78
|
+
return 4;
|
|
79
|
+
}
|
|
80
|
+
function parseSampleTypes(format) {
|
|
81
|
+
if (format === "stencil8") return ["uint"];
|
|
82
|
+
if (format.includes("uint")) return ["uint"];
|
|
83
|
+
if (format.includes("sint")) return ["sint"];
|
|
84
|
+
if (format.includes("depth")) return ["depth", "unfilterable-float"];
|
|
85
|
+
if (/^(r|rg|rgba)16(u|s)norm$/.test(format)) return ["unfilterable-float"];
|
|
86
|
+
return ["float", "unfilterable-float"];
|
|
87
|
+
}
|
|
88
|
+
const FLOAT32_FORMATS = new Set([
|
|
89
|
+
"r32float",
|
|
90
|
+
"rg32float",
|
|
91
|
+
"rgba32float"
|
|
92
|
+
]);
|
|
93
|
+
function getEffectiveSampleTypes(device, format) {
|
|
94
|
+
if (FLOAT32_FORMATS.has(format) && !device.features.has("float32-filterable")) return ["unfilterable-float"];
|
|
95
|
+
return getTextureFormatInfo(format).sampleTypes;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
//#endregion
|
|
99
|
+
export { getEffectiveSampleTypes, getTextureFormatInfo };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/core/texture/textureProps.d.ts
|
|
2
|
+
type TextureProps = {
|
|
3
|
+
size: readonly number[];
|
|
4
|
+
format: GPUTextureFormat;
|
|
5
|
+
viewFormats?: GPUTextureFormat[] | undefined;
|
|
6
|
+
dimension?: GPUTextureDimension | undefined;
|
|
7
|
+
mipLevelCount?: number | undefined;
|
|
8
|
+
sampleCount?: number | undefined;
|
|
9
|
+
};
|
|
10
|
+
//#endregion
|
|
11
|
+
export { TextureProps };
|