From fc77fd37c8f45fd89d0a1efedf618382bf921ba7 Mon Sep 17 00:00:00 2001 From: Konrad Reczko Date: Wed, 7 Jan 2026 10:03:46 +0100 Subject: [PATCH 1/2] fix type and add texturesamplecomparelevel --- packages/typegpu/src/std/index.ts | 1 + packages/typegpu/src/std/texture.ts | 67 ++++++++++++++++++++++++++++- 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/packages/typegpu/src/std/index.ts b/packages/typegpu/src/std/index.ts index 15a04a807d..6ff2e12a99 100644 --- a/packages/typegpu/src/std/index.ts +++ b/packages/typegpu/src/std/index.ts @@ -153,6 +153,7 @@ export { textureSampleBaseClampToEdge, textureSampleBias, textureSampleCompare, + textureSampleCompareLevel, textureSampleLevel, textureStore, } from './texture.ts'; diff --git a/packages/typegpu/src/std/texture.ts b/packages/typegpu/src/std/texture.ts index c4325a1a76..6a07314f63 100644 --- a/packages/typegpu/src/std/texture.ts +++ b/packages/typegpu/src/std/texture.ts @@ -37,6 +37,7 @@ import type { textureDepth2d, textureDepth2dArray, textureDepthCube, + textureDepthCubeArray, textureExternal, textureMultisampled2d, textureStorage1d, @@ -537,7 +538,7 @@ function textureSampleCompareCpu( coords: v3f, depthRef: number, ): number; -function textureSampleCompareCpu( +function textureSampleCompareCpu( texture: T, sampler: comparisonSampler, coords: v3f, @@ -567,6 +568,70 @@ export const textureSampleCompare = dualImpl({ }), }); +function textureSampleCompareLevelCpu( + texture: T, + sampler: comparisonSampler, + coords: v2f, + depthRef: number, +): number; +function textureSampleCompareLevelCpu( + texture: T, + sampler: comparisonSampler, + coords: v2f, + depthRef: number, + offset: v2i, +): number; +function textureSampleCompareLevelCpu( + texture: T, + sampler: comparisonSampler, + coords: v2f, + arrayIndex: number, + depthRef: number, +): number; +function textureSampleCompareLevelCpu( + texture: T, + sampler: comparisonSampler, + coords: v2f, + arrayIndex: number, + depthRef: number, + offset: v2i, +): number; +function textureSampleCompareLevelCpu( + texture: T, + sampler: comparisonSampler, + coords: v3f, + depthRef: number, +): number; +function textureSampleCompareLevelCpu( + texture: T, + sampler: comparisonSampler, + coords: v3f, + arrayIndex: number, + depthRef: number, +): number; +function textureSampleCompareLevelCpu( + _texture: WgslTexture, + _sampler: comparisonSampler, + _coords: v2f | v3f, + _depthRefOrArrayIndex: number, + _depthRefOrOffset?: number | v2i, + _maybeOffset?: v2i, +): number { + throw new Error( + 'Texture comparison sampling with level relies on GPU resources and cannot be executed outside of a draw call', + ); +} + +export const textureSampleCompareLevel = dualImpl({ + name: 'textureSampleCompareLevel', + normalImpl: textureSampleCompareLevelCpu, + codegenImpl: (...args) => stitch`textureSampleCompareLevel(${args})`, + signature: (...args) => ({ + argTypes: args, + returnType: f32, + }), +}); + function textureSampleBaseClampToEdgeCpu< T extends texture2d | textureExternal, >(texture: T, sampler: sampler, coords: v2f): v4f { From b48a4e68df33ca94ce827b8e8eea07d93c223b1a Mon Sep 17 00:00:00 2001 From: Konrad Reczko Date: Wed, 14 Jan 2026 15:23:50 +0100 Subject: [PATCH 2/2] better error --- packages/typegpu/src/std/texture.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/typegpu/src/std/texture.ts b/packages/typegpu/src/std/texture.ts index 6a07314f63..1d8553c242 100644 --- a/packages/typegpu/src/std/texture.ts +++ b/packages/typegpu/src/std/texture.ts @@ -6,7 +6,7 @@ import { type WgslTexture, } from '../data/texture.ts'; import type { TexelData } from '../core/texture/texture.ts'; -import { dualImpl } from '../core/function/dualImpl.ts'; +import { dualImpl, MissingCpuImplError } from '../core/function/dualImpl.ts'; import { f32, u32 } from '../data/numeric.ts'; import { vec2u, vec3u, vec4f, vec4i, vec4u } from '../data/vector.ts'; import { @@ -110,7 +110,7 @@ function sampleCpu( _offsetOrArrayIndex?: v2i | v3i | number, _maybeOffset?: v2i | v3i, ): v4f | number { - throw new Error( + throw new MissingCpuImplError( 'Texture sampling relies on GPU resources and cannot be executed outside of a draw call', ); } @@ -171,7 +171,7 @@ function sampleBiasCpu( _biasOrOffset?: number | v2i | v3i, _maybeOffset?: v2i | v3i, ): v4f { - throw new Error( + throw new MissingCpuImplError( 'Texture sampling with bias relies on GPU resources and cannot be executed outside of a draw call', ); } @@ -289,7 +289,7 @@ function sampleLevelCpu( _offsetOrArrayIndex?: v2i | v3i | number, _maybeOffset?: v2i | v3i, ): v4f | number { - throw new Error( + throw new MissingCpuImplError( 'Texture sampling relies on GPU resources and cannot be executed outside of a draw call', ); } @@ -364,7 +364,7 @@ function textureLoadCpu( _coords: number | v2i | v2u | v3i | v3u, _levelOrArrayIndex?: number, ): TexelData { - throw new Error( + throw new MissingCpuImplError( '`textureLoad` relies on GPU resources and cannot be executed outside of a draw call', ); } @@ -425,7 +425,7 @@ function textureStoreCpu( _arrayIndexOrValue?: number | TexelData, _maybeValue?: TexelData, ): void { - throw new Error( + throw new MissingCpuImplError( '`textureStore` relies on GPU resources and cannot be executed outside of a draw call', ); } @@ -472,7 +472,7 @@ function textureDimensionsCpu( _texture: WgslTexture | WgslStorageTexture | WgslExternalTexture, _level?: number, ): number | v2u | v3u { - throw new Error( + throw new MissingCpuImplError( '`textureDimensions` relies on GPU resources and cannot be executed outside of a draw call', ); } @@ -553,7 +553,7 @@ function textureSampleCompareCpu( _depthRefOrOffset?: number | v2i, _maybeOffset?: v2i, ): number { - throw new Error( + throw new MissingCpuImplError( 'Texture comparison sampling relies on GPU resources and cannot be executed outside of a draw call', ); } @@ -617,7 +617,7 @@ function textureSampleCompareLevelCpu( _depthRefOrOffset?: number | v2i, _maybeOffset?: v2i, ): number { - throw new Error( + throw new MissingCpuImplError( 'Texture comparison sampling with level relies on GPU resources and cannot be executed outside of a draw call', ); } @@ -635,7 +635,7 @@ export const textureSampleCompareLevel = dualImpl({ function textureSampleBaseClampToEdgeCpu< T extends texture2d | textureExternal, >(texture: T, sampler: sampler, coords: v2f): v4f { - throw new Error( + throw new MissingCpuImplError( 'Texture sampling with base clamp to edge is not supported outside of GPU mode.', ); }